RubyObject from Java to Ruby

Hi,

I have a RubyObject in Java, but now I want to bring it back to the Ruby
side, in other words, I would like to use JRuby’s eval and somehow
reference
this RubyObject in the ruby side.

For example I would like to call a method from my RubyObject using Ruby
and
not the JRuby Java API (DynamicMethod).

Is that possible somehow?

Thanks,

-Sergio Oliveira Jr.

Sergio Oliveira wrote:

Is that possible somehow?
When you bind it through BSF or JSR223, is it getting re-wrapped? If so
that would be a bug…but you should be able to call java_object on it
to get the actual RubyObject back out again.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I may be missing something or that may not be possible/desired.

I do something like this:

Object rubyObject = ruby.eval(“MyObject.new”);

// do many things here…

// then I want to manipulate and work with the rubyObject in Ruby and
not in
Java, but It was not bound to any variable in the Ruby side.

Any way to take a RubyObject in Java to the Ruby side so I can use it
for
example inside an eval call?

I could not find this method java_object. From what class it belongs? Is
there a JRuby JavaDoc API somewhere?

Since my objects will be short lived web actions, I am considering
keeping
them in a global map in the Ruby side, so that I also have the object
saved
and easily accessible in the Ruby side. When my java object is finalized
by
GC I will remove the object from this map in the ruby map.

Thanks very much!

-Sergio

On Wed, May 21, 2008 at 12:35 AM, Charles Oliver N. <

On Wed, May 21, 2008 at 7:55 AM, Sergio Oliveira
[email protected] wrote:

I may be missing something or that may not be possible/desired.

I do something like this:

Object rubyObject = ruby.eval(“MyObject.new”);

I am not saying this is the best way but it should give you ideas:

Object rubyObject = ruby.eval("$object = MyObject.new");

// do stuff …

ruby.eval("$object.so_some_more");

Any way to take a RubyObject in Java to the Ruby side so I can use it for
example inside an eval call?

I could not find this method java_object. From what class it belongs? Is
there a JRuby JavaDoc API somewhere?

It is only on ruby side of things…not a Java method. You probably
don’t need it in this case.

Since my objects will be short lived web actions, I am considering keeping
them in a global map in the Ruby side, so that I also have the object saved
and easily accessible in the Ruby side. When my java object is finalized by
GC I will remove the object from this map in the ruby map.

That works. I think you will need to be careful about makign sure you
do not retain references since you will have one reference from Ruby
and one from Java side.

-Tom


Blog: http://www.bloglines.com/blog/ThomasEEnebo
Email: [email protected] , [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs