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, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



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

def self.description
  <<-EOD
    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.
  EOD
end

.regexpObject



13
14
15
# File 'lib/byebug/commands/method.rb', line 13

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

.short_descriptionObject



31
32
33
# File 'lib/byebug/commands/method.rb', line 31

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

Instance Method Details

#executeObject



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

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