Hello all.
Pleased to announce the release of “ri_for” gem v 0.6.0
Changes:
0.6.0: jruby support, add File.method(:delete).ri_for
more information see GitHub - rdp/ri_for: allows you to grab a method's docu at runtime
README contents:
The ri_for gem allows “runtime documentation lookup”, it show a method’s
source code/comments, ri (if available), arity, parameters,
etc. all at runtime (for example within an irb session).
Don’t know what a method does? Look it up!
It has proven quite useful, and I wouldn’t do a ruby-debug session
without it–you might like it.
Examples:
File.ri_for :delete
sig: File.delete arity -1
appears to be a c method
Searching ri for
sig: File.delete arity -1
…
----------------------------------------------------------- File::delete
File.delete(file_name, …) => integer
File.unlink(file_name, …) => integer
Deletes the named files, returning the number of names passed as
arguments. Raises an exception on any error. See also +Dir::rmdir+.
(end ri)
=> “sig: File.delete arity -1”
(or alternatively use >> File.method(:delete).ri_for)
or, given this dynamically generated class, it can still show runtime
parameter information:
class A;
def go(a); end;
end
A.new.ri_for :go
sig: A#go arity 1
def go(a)
do nothing
end
Parameters: go(a)
Searching ri for
sig: A#go arity 1
…
Nothing known about A
(end ri)
=> “Parameters: go(a)”
Or (my favorite) use it within debug session:
74 assert(true == false)
(rdb:1) ri_for :assert
#<Method: StoreControllerTest(Test::Unit::Assertions)#assert>
arity: -2
ri for Test::Unit::Assertions#assert
------------------------------------------ Test::Unit::Assertions#assert
assert(boolean, message=nil)
From gem test-unit-2.0.1
Asserts that +boolean+ is not false or nil.
Example:
assert [1, 2].include?(5)
(end ri)
def assert(boolean, message = nil)
_wrap_assertion do
assert_block(“assert should not be called with a block.”) do
(not block_given?)
end
assert_block(build_message(message, “<?> is not true.”, boolean)) {
boolean }
end
end
Parameters: assert(boolean, message = nil)
Thus, you can look at methods’ source/rdocs without having to run the
methods and step into them. Deftly convenient.