The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
IRB+RI: still room for improvement - better completion, method definition site discovery

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
IRB+RI: still room for improvement - better completion, method definition site discovery Posted: Nov 6, 2006 5:54 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: IRB+RI: still room for improvement - better completion, method definition site discovery
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass

Advertisement

Yes, everybody and his dog has hacked his .irbrc in order to use RI and complete methods. You've seen it in rubygarden and then in wirble.

But really, typing

 Object.ri "object_id"

is way too much work.

sheepman showed the way to combine method completion and RI, and here's my improvement on it: thanks to FastRI*1 being much faster than RI, you can discover where a method came from and get the corresponding documentation: irb-ri-completion.png

You use it like this:

>> 1.0.ri_[TAB]
1.0.ri_"%"        1.0.ri_class          1.0.ri_instance_variable_set   1.0.ri_respond_to?
1.0.ri_"*"         1.0.ri_clone          1.0.ri_instance_variables      1.0.ri_ri_
1.0.ri_"**"        1.0.ri_coerce         1.0.ri_integer?                1.0.ri_round
>> 1.0.ri_p[TAB]
1.0.ri_prec               1.0.ri_prec_i             1.0.ri_protected_methods  
1.0.ri_prec_f             1.0.ri_private_methods    1.0.ri_public_methods

For each #method, you'll get the corresponding #ri_method completion. You can also do

 >> r 'String#strip'

but now also with completion.

Finding out where the methods come from.

If you have

a = {}

with previous RI+irb hacks you might have tried

Hash.ri "inject"

Leaving the unneeded typing aside, you'd have obtained

Nothing known about Hash#inject

In other words: you'd have to know where the method comes from, that is, in which class/module it was defined. Now, that's easy for Enumerable#inject, but did you know about e.g. Precision#prec?

My irbrc hack looks for the method in all the ancestors of the receiver's class, so you don't need to know where the method you knew (maybe) nothing about (besides the name) to begin with comes from.

This is where FastRI enters the picture: the older RI can take over one second per lookup even when all your RI docs are cached and you don't hit the disk, and much longer (about 5 seconds for me) for the first one.

So

>> 1.0.ri_object_id

could take over 10 seconds with RI. It's under half a second for FastRI*2 -- and half of that time is actually spent formatting the description.


Read more...

Read: IRB+RI: still room for improvement - better completion, method definition site discovery

Topic: Ultimate Programmer Reference Previous Topic   Next Topic Topic: Deprecations in Rails 1.2

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use