Sha256: 187fa7b3568bc2305484bff14f9f3a0f0ae20c337e96075b45cfda6dc1c08c19

Contents?: true

Size: 1.18 KB

Versions: 12

Compression:

Stored size: 1.18 KB

Contents

class Object
  ANSI_BOLD       = "\033[1m"
  ANSI_RESET      = "\033[0m"
  ANSI_LGRAY    = "\033[0;37m"
  ANSI_GRAY     = "\033[1;30m"

  # Print object's methods
  def pm(*options)
    methods = self.methods
    methods -= Object.methods unless options.include? :more
    filter = options.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
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rubabel-0.4.3 lib/rubabel/pm.rb
rubabel-0.4.2 lib/rubabel/pm.rb
rubabel-0.4.1 lib/rubabel/pm.rb
rubabel-0.4.0 lib/rubabel/pm.rb
rubabel-0.3.0 lib/rubabel/pm.rb
rubabel-0.2.2 lib/rubabel/pm.rb
rubabel-0.2.1 lib/rubabel/pm.rb
rubabel-0.2.0 lib/rubabel/pm.rb
rubabel-0.1.6 lib/rubabel/pm.rb
rubabel-0.1.5 lib/rubabel/pm.rb
rubabel-0.1.1 lib/rubabel/pm.rb
rubabel-0.1.0 lib/rubabel/pm.rb