Java Reflection in Ruby

C

Charlie Squires

For part of an application I'm working on I am looking to use Java
Reflection to get method information from a .class file. And I'm trying to
find a way to do this with Ruby (have Ruby use Java reflection to get the
info). Anyone have suggestions as to how to do it?

Thanks in advance,
Charlie
 
D

Dean Wampler

You might look at the JRuby project, which is doing a port of Ruby on
top of the JVM. They might already have library code to do this. I
don't know one way or the other.

dean
 
A

Alexandru Popescu

#: Charlie Squires changed the world a bit at a time by saying on 10/28/2005 8:07 PM :#
For part of an application I'm working on I am looking to use Java
Reflection to get method information from a .class file. And I'm trying to
find a way to do this with Ruby (have Ruby use Java reflection to get the
info). Anyone have suggestions as to how to do it?

Thanks in advance,
Charlie

Why would you do this?

/alex
 
S

SAKURAI Masashi

Hi,
For part of an application I'm working on I am looking to use Java
Reflection to get method information from a .class file.

Using yajb (http://raa.ruby-lang.org/project/yajb/), you can use Java
Reflection API from ruby (attached code).

If you want to build a Class object from a byte array, you need to
implement the custom class loader in Java.

Although yajb can make a subclass of any class in Java, I can not show
the implementation of java.lang.ClassLoader on yajb, because of a bug
of yajb. I'm going to fix it.


######

require 'yajb/jbridge'
include JavaBridge
jimport 'java.io.*'

klass = :String.jclass.getClass
puts klass.getName

puts "=====================(field)"
klass.getDeclaredFields.each {|i|
puts i.getName
}

puts "=====================(method)"
klass.getDeclaredMethods.each {|i|
puts i.getName
}
 
C

Charlie Squires

Thanks, I will give that a try.


SAKURAI Masashi said:
Hi,


Using yajb (http://raa.ruby-lang.org/project/yajb/), you can use Java
Reflection API from ruby (attached code).

If you want to build a Class object from a byte array, you need to
implement the custom class loader in Java.

Although yajb can make a subclass of any class in Java, I can not show
the implementation of java.lang.ClassLoader on yajb, because of a bug
of yajb. I'm going to fix it.


######

require 'yajb/jbridge'
include JavaBridge
jimport 'java.io.*'

klass = :String.jclass.getClass
puts klass.getName

puts "=====================(field)"
klass.getDeclaredFields.each {|i|
puts i.getName
}

puts "=====================(method)"
klass.getDeclaredMethods.each {|i|
puts i.getName
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top