Java reflection on a JRuby object

Hi,

Probably a dumb question, but is it possible to get declared fields
using Java reflection on a JRuby object?

To illustrate what I

On Thu, Mar 17, 2011 at 4:08 PM, Sbastien Le Callonnec [email protected]
wrote:

import java.lang.reflect.Field;
} catch (Exception e) {

end
be_kind_of(Field)
a JRuby script driving a third-party Java library that uses reflection)
final Object ivar = sc.runScriptlet(“class IVar; attr_accessor
:foo; end; x=IVar.new;x.foo=123;x”);
@SuppressWarnings(“unchecked”)
final List ivars = (List) sc.callMethod(ivar,
“instance_variables”);
for (Object iv : ivars) {
System.out.println(iv.getClass().getName() + " " + iv);
}

Kind regards

robert


remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

On Fri, Mar 18, 2011 at 9:40 AM, Robert K.
[email protected] wrote:

 }

end
@reflection.find_declared_field(my_class, ‘my_field’).should
(Obviously, this would be much easier using pure JRuby, but I want to write
a JRuby script driving a third-party Java library that uses reflection)

final Object ivar = sc.runScriptlet(“class IVar; attr_accessor
:foo; end; x=IVar.new;x.foo=123;x”);
@SuppressWarnings(“unchecked”)
final List ivars = (List) sc.callMethod(ivar,
“instance_variables”);
for (Object iv : ivars) {
System.out.println(iv.getClass().getName() + " " + iv);
}

Sorry, intermediate version of the code posted. I wanted to post this
one

final Object obj = sc.runScriptlet("class IVar; attr_accessor

:foo; end; x=IVar.new;x.foo=123;x");
@SuppressWarnings(“unchecked”)
final List ivars = (List) sc.callMethod(obj,
“instance_variables”);

for (final String iv : ivars) {
  System.out.println(iv);
}

Cheers

robert


remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

On 18/03/2011 08:43, Robert K. wrote:

 final Object obj = sc.runScriptlet("class IVar; attr_accessor

:foo; end; x=IVar.new;x.foo=123;x");
@SuppressWarnings(“unchecked”)
final List ivars = (List) sc.callMethod(obj,
“instance_variables”);

 for (final String iv : ivars) {
   System.out.println(iv);
 }

Thanks Robert. However I cannot change the Java class that does the
reflection on the JRuby object. I would therefore expect some JRuby
trickery to be able to call