17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/irt/commands/ri.rb', line 17
def ri(arg, literal=false)
ensure_session
raise IRT::NotImplementedError, "No available ri_command_format for this system." unless IRT.ri_command_format
case
when arg.match(/^\d+$/)
if @@choices_map.key?(arg)
to_search = @@choices_map[arg]
else
raise IndexError, "No such method index -- [#{arg}]"
end
when literal
if output = process_ri(arg)
puts(output)
return
end
when arg =~ /^[A-Z]\w+\#[^.]+/
to_search = arg
when arg !~ /\./
begin
obj = eval arg, IRB.CurrentContext.workspace.binding
to_search = obj.class
rescue NameError
if output = process_ri(arg)
puts(output)
return
end
raise
end
else
segm = arg.split('.')
to_search = segm.pop
receiver = eval segm.join('.'), IRB.CurrentContext.workspace.binding
raise NoMethodError, %(undefined method '#{to_search}' for #{receiver.inspect}:#{receiver.class}) \
unless receiver.respond_to? to_search.to_sym
meth = receiver.method(to_search.to_sym).inspect
meth = meth.match(/^\#<Method: (.+)>$/)[1]
if m = meth.match(/\((.+)\)(.+)/)
to_search = m[1] + m[2]
else
to_search = meth
end
end
puts process_ri(to_search) || 'Nothing found!'
end
|