From: David Masover Date: 2010-04-26T05:23:40+09:00 Subject: Re: DrX, an object inspector On Sunday 25 April 2010 02:41:07 am Charles Oliver Nutter wrote: > On Sat, Apr 24, 2010 at 10:38 AM, David Masover wrote: > >> For getting the data, you don't even need to write an extension to > >> JRuby. The "jruby" library gives you introspective access to all > >> objects at a very direct level: > > > > It seems like this should be possible to do from bare Ruby, in a portable > > way. Clumsy, but possible. For example, as long as people don't get smart > > and use Ruby 1.9's BasicObject, you can do this: > > No, I'm pretty sure this isn't possible on regular Ruby. Ah, wishful thinking of my part, then. > What's > happening in JRuby is that you're getting direct access to the Java > object representing a Ruby class or object, and you then can do > anything to that object you'd normally have to write Java code for. I've raised this question before, and people seem to disagree with me, but: > # changing the object's class(!?) > class Foo; end > p obj.class # => 'Object' > obj_ref.setMetaClass(JRuby.reference(Foo)) > p obj.class # => 'Foo' I think it should be possible to do that from within Ruby. But I can't even get most people behind this suggestion: class A; end class B; end A.instance_method(:to_s).bind(B.new) That gives me a type error, which just seems bizarre, especially after the relative freedom of JavaScript. Ah, well.