Class: Byebug::MethodCommand

Inherits:
Command
  • Object
show all
Includes:
Helpers::EvalHelper
Defined in:
lib/byebug/commands/method.rb

Overview

Show methods of specific classes/modules/objects.

Instance Attribute Summary

Attributes inherited from Command

#processor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::EvalHelper

#error_eval, #multiple_thread_eval, #separate_thread_eval, #silent_eval, #warning_eval

Methods inherited from Command

#arguments, columnize, #context, #frame, help, #initialize, match, to_s

Methods included from Helpers::StringHelper

#camelize, #deindent, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/byebug/commands/method.rb', line 19

def self.description
  <<-DESCRIPTION
    m[ethod] (i[nstance][ <obj>]|<class|module>)

    #{short_description}

    When invoked with "instance", shows instance methods of the object
    specified as argument or of self no object was specified.

    When invoked only with a class or module, shows class methods of the
    class or module specified as argument.
  DESCRIPTION
end

.regexpObject



15
16
17
# File 'lib/byebug/commands/method.rb', line 15

def self.regexp
  /^\s* m(?:ethod)? \s+ (i(:?nstance)?\s+)?/x
end

.short_descriptionObject



33
34
35
# File 'lib/byebug/commands/method.rb', line 33

def self.short_description
  "Shows methods of an object, class or module"
end

Instance Method Details

#executeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/byebug/commands/method.rb', line 37

def execute
  obj = warning_eval(@match.post_match)

  result =
    if @match[1]
      prc("method.methods", obj.methods.sort) { |item, _| { name: item } }
    elsif !obj.is_a?(Module)
      pr("variable.errors.not_module", object: @match.post_match)
    else
      prc("method.methods", obj.instance_methods(false).sort) do |item, _|
        { name: item }
      end
    end
  puts result
end