The scope of metaprogramming in JRuby

All,

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.

Thanks,
Wes


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Dec 16, 2009 at 10:04 AM, Wes G. [email protected] wrote:

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.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Oliver N. wrote:

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?

Wes


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Dec 16, 2009 at 11:30 AM, Wes G. [email protected] wrote:

Thanks Charlie. Â Is there any metaprogramming that can’t be done in JRuby?

Nothing you can’t do in regular Ruby :slight_smile:

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Dec 16, 2009 at 6:38 PM, Charles Oliver N.
[email protected] wrote:

On Wed, Dec 16, 2009 at 11:30 AM, Wes G. [email protected] wrote:

Thanks Charlie. Is there any metaprogramming that can’t be done in JRuby?

Nothing you can’t do in regular Ruby :slight_smile:

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