Prev: [BUG] Segmentation fault
Next: ya config file parser
From: Jakub Pavlik jn. on 21 Apr 2010 14:15 > On 4/19/10, Mooffie n/a <mooffie(a)gmail.com> wrote: > > DrX is an object inspector (and a source-code browser). > > > > See screenshots at its homepage: > > > > http://drx.rubyforge.org > > Ooo, pretty colors! > > Here is my feedback: > > Is there any chance you'll extend this to show an object's contents > instead of or in addition to it's class/type? > > You should consider using the EDITOR or VISUAL environment variables > instead of DRX_EDITOR_COMMAND. I would suggest not to replace program's private environment variable with the more general ones, but to look first for DRX_EDITOR_COMMAND and if it is not set, take EDITOR or VISUAL. It is possible, that from some reason I want DrX to use some other text editor than the one used by most other programs I use... > > The size and style drop-down boxes don't work for me if I close and > then re-open drx a second time from within irb. > > Please turn drop shadows on by default. > > You ought to provide a drx command so I can launch it directly instead > of invoking it via irb. > > Excellent work! This program is awesome. J.Pavlik -- Napřed přivaž velblouda pevně ke stromu, a teprve potom ho odevzdej do ochrany Boží. (Muhamad; citováno v knize M. Nevrlého Karpatské hry)
From: David Espada on 21 Apr 2010 16:49 El miércoles 21 de abril, Mooffie n/a escribió: >> Any plan to extend it for JRuby?.... 0:D > > I'm not familiar with JRuby, but it was always on my mind to look into > it, so the short answer to your question is "yes". Great news! Thank you for so useful little gem. -- David
From: David Masover on 24 Apr 2010 11:38 On Wednesday 21 April 2010 11:20:12 pm Charles Oliver Nutter wrote: > On Tue, Apr 20, 2010 at 10:44 PM, Mooffie n/a <mooffie(a)gmail.com> wrote: > > David Espada wrote: > >> Any plan to extend it for JRuby?.... 0:D > > > > I'm not familiar with JRuby, but it was always on my mind to look into > > it, so the short answer to your question is "yes". > > > > DrX is composed of three independent components (GUI; GraphViz DOT > > generation; A helper C extension) exactly for this reason. While the > > current GUI, written in Tk, probably isn't portable, it isn't a > > stumbling block. > > 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: > > require 'jruby' > > # no JRuby on this machine, so I'm doing this from memory > some_str = 'hello!' > ref = JRuby.reference(some_str) > 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. For example, as long as people don't get smart and use Ruby 1.9's BasicObject, you can do this: Object.instance_method(:methods).bind('foo').call That takes care of things like Builder's BlankSlate object, though: Object.instance_method(:methods).bind(BlankSlate.new).call => ["__send__", "instance_eval", "__id__"] BlankSlate itself hints at other ways to abuse Ruby for similar effects -- for instance, I couldn't readily find a way to discover where a method was originally defined, and whether it's been overridden, but it seems likely that if I could get my fangs deep into things like method_added before anything else was loaded, I could generate this kind of map. I might be missing what you're trying to do, though.
From: Charles Oliver Nutter on 25 Apr 2010 03:41 On Sat, Apr 24, 2010 at 10:38 AM, David Masover <ninja(a)slaphack.com> 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. 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. Now that I'm on my machine, here's a more extensive example: require 'jruby' class MyObject def foo 'hello' end end obj = MyObject.new cls = obj.class obj_ref = JRuby.reference obj cls_ref = JRuby.reference cls # accessing the raw method table on a class methods = cls_ref.getMethods # this was the ".methods" call previously p methods.class # => Java::JavaUtilConcurrent::ConcurrentHashMap foo_method = methods['foo'] # foo_method is an instance of our internal method object p foo_method.call(JRuby.runtime.current_context, obj, cls_ref, 'foo') # => 'hello' # changing the object's class(!?) class Foo; end p obj.class # => 'Object' obj_ref.setMetaClass(JRuby.reference(Foo)) p obj.class # => 'Foo' # modifying the current scope scope = JRuby.runtime.current_context.current_scope p scope.static_scope.variables.to_a # => ["obj", "cls", "obj_ref", "cls_ref", "methods", "foo_method", "scope"] index = scope.static_scope.variables.to_a.index('scope') scope.set_value_depth_zero('hello', index) p scope # => 'hello' ...and so on. Essentially anything you can call from Java, you can call from Ruby once you have the appropriate reference, so you should be able to programmatically walk all of the JRuby runtime structures and any Ruby or Java objects they reference without writing any Java code. - Charlie
From: Mooffie n/a on 25 Apr 2010 04:53
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/. |