require 'jruby'Whoops. And that's just the beginning. Are you interested in investigating the current call frame or activation frame (DynamicScope in JRuby):
JRuby::runtime.cache_map
require 'jruby'Of course, you can call all accessible (and some inaccessible) methods on these objects, just like if you were working with it from Java. Use the API's and take a look. You can change things without problem.
p JRuby::runtime.current_context.current_frame
a = 1
p JRuby::runtime.current_context.current_scope
And that also brings us to one of the easiest examples of evil.rb, changing the frozen flag on a Ruby object. Well, with the reference method, that's easy:
require 'jruby'JRuby::reference will return the same object sent in, wrapped in a Java Integration layer, meaning that you can inspect and modify it to your hearts like. In this way, you can get at the internals of JRuby in the same way you can using evil.rb for MRI. And I guess these features should mainly be used for looking and learning about the internals of JRuby.
str = "foo"
str.freeze
puts str.frozen?
JRuby::reference(str).setFrozen(false)
puts str.frozen?
So, have fun and don't be evil (overtly).
2 kommentarer:
But..but...isn't that breaking encapsulation? Won't the Java programmers have a fit?
:-P
Yup, very great stuff. :)
Skicka en kommentar