From: Mooffie n/a Date: 2010-04-25T17:53:42+09:00 Subject: Re: DrX, an object inspector David Masover wrote: > On Wednesday 21 April 2010 11:20:12 pm Charles Oliver Nutter wrote: > > ref.class # now org.jruby.RubyString > > ref.methods # now includes all Java-land methods on RubyString > > cls = ref.metaclass # an org.jruby.RubyClass instance > > cls.methods # should be the internal method table > > It seems like this should be possible to do from bare Ruby, in a > portable way. > Clumsy, but possible. How, for example, can you find an object's class using pure Ruby? The problem with Ruby's #class is that it skips singletons. Example: s = "blah" def s.whatever; 666; end p s.class The above will print "String", but it's an error: the class should be some singleton. (Doing "class << s; self; end" isn't a solution because it alters the object model: it *creates* a singleton if none yet exists.) Though maybe there *is* a way to find an object's class, I don't know (I still consider myself a Ruby newbie). > > cls.methods # should be the internal method table > > It seems like this should be possible to do from bare Ruby, in a > portable way. As another example, consider this: module M def whatever; 666; end undef_method :whatever end M.instance_methods() won't report the method 'whatever', whereas Ruby keeps a stub under that name. I want to see it. When I started writing DrX my intention was to figure out how Ruby and/or MRI works. So high-fidelity was important to me. In fact, I simply wanted to see the C structures. I'm not interested in approximation. (Though nothing prevents replacing the C extension with a pure-Ruby implementation.) -- Posted via http://www.ruby-forum.com/.