A “ruby method describer”–this gem allows you to introspect methods while within irb or ruby-debug. It reveals everything conceivably known about that method. This includes source, ri, arity, rdoc comments (on 1.9), etc. etc.
For me it has proved quite useful, and I wouldn’t leave home without it [try it–you might really like it].
Examples: >>
class A;
def go(a); end;
end
>> A.desc_method :go
# it outputs everything it knows about it...arity, source, RI, etc.
ri for A#go Nothing known about A (end ri) #<UnboundMethod: A#go> arity: 1 A#go a proc { |a|
# do nothing
}
an example in 1.9: >> File.desc_method :delete ri for File.delete ———————————————————– File::delete
File.delete(file_name, ...) => integer
File.unlink(file_name, ...) => integer
From Ruby 1.9.1
Deletes the named files, returning the number of names passed as
arguments. Raises an exception on any error. See also +Dir::rmdir+.
(end ri) #<Method: File.delete> arity: -1 appears to be a c method #parameters signature: delete( [[:rest]] )
Installation/usage:=====
Installation: $ gem install rogerdpack-desc_method Usage: >> require ‘desc_method’ >> Class.desc_method :method_name # class or instance method name … >> instance.desc_method :instance_method_name …
other goodies also included: Class.desc_class method # outputs descriptive information about that class–ex: >> Object.desc_class # outputs RI, methods, etc. or >> Object.desc_class :verbose => true # outputs RI, method lists including inherited methods, ancestors, constants
Kernel#method is monkey patched to output a “separator” between its inherited and non inherited methods–i.e. >> method
> [:first, :second, :after_this_are_inherited>>>>>, :some_inherited_method, :another_inherited_method] # adds in the separator
This gem wraps (in a very convenient way) functionality provided by Method#source_location, ruby2ruby, etc. Also thanks to manvenu for some original code inspiration, SourceRef (MBARI), and ruby-debug, who made this possible. Thanks guys!
Comments/suggestions welcome rogerdpack on gmail or github