| Class | Ruva::VM::Types::ConstStringRef |
| In: |
lib/ruva/types.rb
|
| Parent: | ObjectRef |
Unwrap the supplied java/lang/String ObjectRef str, yield the resulting Ruby string, then wrap and return the result of the yield as a reference of the same type as the original.
# File lib/ruva/types.rb, line 174
174: def rewrap(vm, str)
175: str.class.new(str.clz, {}, yield(unwrap(str))).link(vm)
176: end
Unwrap the supplied java/lang/String ObjectRef str to a Ruby string. The supplied reference doesn‘t have to be a ConstStringRef - any String reference will do.
# File lib/ruva/types.rb, line 163
163: def unwrap(str)
164: unless str.clz.name == 'java/lang/String'
165: raise VM::TypeError, "Expected instance of java/lang/String"
166: end
167:
168: (str.get_field('value','[C') || []).map { |c| c.chr }.join.rstrip
169: end
Wrap the supplied Ruby string str in a ConstStringRef.
# File lib/ruva/types.rb, line 156
156: def wrap(vm, str)
157: new(@@string_class ||= vm.find_class('java/lang/String'), {}, str).link(vm)
158: end
TODO these semantics are broken. It should be for interned strings, but for all interned strings. Maybe VMString should intern by wrapping in a ConstStringRef…
# File lib/ruva/types.rb, line 205
205: def ==(other)
206: other.is_a?(ObjectRef) && other.identity_hash == identity_hash
207: end
# File lib/ruva/types.rb, line 198
198: def identity_hash
199: @ident_hash ||= get_field('value','[C').hash
200: end