Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/rubabel/pm.rb
Constant Summary collapse
- ANSI_BOLD =
"\033[1m"
- ANSI_RESET =
"\033[0m"
- ANSI_LGRAY =
"\033[0;37m"
- ANSI_GRAY =
"\033[1;30m"
Instance Method Summary collapse
-
#pm(*options) ⇒ Object
Print object’s methods.
Instance Method Details
#pm(*options) ⇒ Object
Print object’s methods
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rubabel/pm.rb', line 9 def pm(*) methods = self.methods methods -= Object.methods unless .include? :more filter = .select {|opt| opt.kind_of? Regexp}.first methods = methods.select {|name| name =~ filter} if filter data = methods.sort.collect do |name| method = self.method(name) if method.arity == 0 args = "()" elsif method.arity > 0 n = method.arity args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")})" elsif method.arity < 0 n = -method.arity args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")}, ...)" end klass = $1 if method.inspect =~ /Method: (.*?)#/ [name, args, klass] end max_name = data.collect {|item| item[0].size}.max max_args = data.collect {|item| item[1].size}.max data.each do |item| print " #{ANSI_BOLD}#{item[0].rjust(max_name)}#{ANSI_RESET}" print "#{ANSI_GRAY}#{item[1].ljust(max_args)}#{ANSI_RESET}" print " #{ANSI_LGRAY}#{item[2]}#{ANSI_RESET}\n" end data.size end |