Java Reflection in Ruby

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

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

···

On 10/28/05, Charlie Squires <mercury542@yahoo.com> wrote:

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

--
Dean Wampler
http://www.aspectprogramming.com

#: 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

···

--
.w( the_mindstorm )p.

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
}

--
SAKURAI, Masashi (family, given)
m.sakurai@dream.com

Dean Wampler wrote:

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.

Zach

Thanks, I will give that a try.

"SAKURAI Masashi" <m.sakurai@dream.com> wrote in message
news:200510290359.j9T3xgAQ015180@mx52.ms.so-net.ne.jp...

···

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
}

--
SAKURAI, Masashi (family, given)
m.sakurai@dream.com