开发者

Undefined method for ri inside of IRB

Inside of the interactive ruby console if i type ri then i get an undefined method error, do i explicitly have to install documentation somewhere to get t开发者_如何转开发his to work?

irb(main):015:0* ri --help
NoMethodError: undefined method `-@' for nil:NilClass
    from (irb):15
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:295
irb(main):016:0> ri Array
NoMethodError: undefined method `ri' for main:Object
    from (irb):16
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:295


You probably do not want to do that. What you should be doing is exiting to the shell (or preferably, open a new terminal tab or screen session) and running ri separately, which is a program, from there. If you really, really, want to do what you're doing, you can always use backticks to run ri --help, or any other shell command.

irb(main):015:0* `ri --help`


In fact ORI gem can bring RI to your IRB console and give some more neat class exploration functions.

Watch intro screencast.

Setup (~/.irbrc)

require "rubygems"
require "ori"

Request RI on a Class

Array.ri
String.ri
[].ri
"".ri
5.ri

Request RI on a Method

String.ri :upcase
"".ri :upcase
[].ri :sort
Hash.ri :[]

Request Interactive Method List

String.ri //
"".ri //
"".ri /case/
"".ri /^to_/
User.ri /^validates_/

etc.


Just --help:

irb(main):040:0> --help

Enter the method name you want to look up.
You can use tab to autocomplete.
Enter a blank line to exit.

>> Array
←[0m←[1;32mArray < Object←[m

(from gem backports-1.18.2)
------------------------------------------

To return into IRB, I pressed Crtl+C, but there probably is some some quit-command.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜