1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/commands/stat.rb
Kyrylo Silin 905bab4d7c Add support of aliases for Method
Fix issue #367 (stat command should display the list of aliases for a
given method).

You can get a list of aliases for a method like this:

  pry(main)> stat Array#map
  Method Information:
  --
  Name: map
  Alias: collect
  Owner: Array
  Visibility: public
  Type: Unbound
  Arity: 0
  Method Signature: map()
  Source Location: Not found.

Note that `Method#aliases` returns an Array of strings on MRI 1.8 and
friends, while on MRI 1.9 it returns an Array of symbols.

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
2012-08-26 00:02:39 +03:00

35 lines
1 KiB
Ruby

class Pry
Pry::Commands.create_command "stat" do
group 'Introspection'
description "View method information and set _file_ and _dir_ locals."
command_options :shellwords => false
banner <<-BANNER
Usage: stat [OPTIONS] [METH]
Show method information for method METH and set _file_ and _dir_ locals.
e.g: stat hello_method
BANNER
def options(opt)
method_options(opt)
end
def process
meth = method_object
aliases = meth.aliases
output.puts unindent <<-EOS
Method Information:
--
Name: #{meth.name}
Alias#{ "es" if aliases.length > 1 }: #{ aliases.any? ? aliases.join(", ") : "None." }
Owner: #{meth.owner ? meth.owner : "Unknown"}
Visibility: #{meth.visibility}
Type: #{meth.is_a?(::Method) ? "Bound" : "Unbound"}
Arity: #{meth.arity}
Method Signature: #{meth.signature}
Source Location: #{meth.source_location ? meth.source_location.join(":") : "Not found."}
EOS
end
end
end