A couple of days ago a friend asked me what level of Ruby metaprogramming
was achievable in JRuby. Â I wasn’t sure how to answer him.
Are there limitations on standard Ruby metaprogramming practices when using
JRuby?
Do all metaprogramming actions (e.g. class modifications, etc.) get resolved
at compile time or does any byte code modification happen on the fly?
Any helfpul reference material is greatly appreciated as well.
There’s probably information on the wiki about this, perhaps in the
JRuby internal design section, but here’s the simple answer:
JRuby does not generate full-on Java classes+bytecode for Ruby code
when it is loaded. Instead, we just generate “chunks” of bytecode for
method bodies, and then assemble them using our own dynamic class
structures (which are mostly just glorified hashtables). So none of
the usual metaprogramming features require bytecode manipulation…we
just manipulate those structures.
Future versions of JRuby will be able to generate normal Java classes
from Ruby source (rather than the “bag-o-methods” .class we produce
today). In that case, Ruby-side metaprogramming will still work
exactly the same, but only classes we can see at compile (parse) time
will be added to the Java class.
Any helfpul reference material is greatly appreciated as well.
just manipulate those structures.
Future versions of JRuby will be able to generate normal Java classes
from Ruby source (rather than the “bag-o-methods” .class we produce
today). In that case, Ruby-side metaprogramming will still work
exactly the same, but only classes we can see at compile (parse) time
will be added to the Java class.
Charlie
Thanks Charlie. Is there any metaprogramming that can’t be done in
JRuby?
Thanks Charlie. Is there any metaprogramming that can’t be done in JRuby?
Nothing you can’t do in regular Ruby
Yeah, there should be 100% match. Furthermore, Wes, if you have
anything (metaprogramming-related) that you could do in MRI and it
doesn’t work in JRuby, this is a bug that should be filed and fixed.
Ideally, tests for such things should go to the shared RubySpecs
project to help out all Ruby implementations out there.
But so far, I’m not aware of any limitations in JRuby in that regard.
Thanks,
–Vladimir
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.