Class: Byebug::VarCommand::ConstCommand

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

Overview

Shows constants

Instance Attribute Summary

Attributes inherited from Command

#processor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::EvalHelper

#error_eval, #silent_eval, #single_thread_eval, #thread_safe_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



20
21
22
23
24
25
26
# File 'lib/byebug/commands/var/const.rb', line 20

def self.description
  <<-EOD
    v[ar] c[onstant]

    #{short_description}
  EOD
end

.regexpObject



16
17
18
# File 'lib/byebug/commands/var/const.rb', line 16

def self.regexp
  /^\s* c(?:onst)? (?:\s+ (.+))? \s*$/x
end

.short_descriptionObject



28
29
30
# File 'lib/byebug/commands/var/const.rb', line 28

def self.short_description
  'Shows constants of an object.'
end

Instance Method Details

#executeObject



32
33
34
35
36
37
38
39
40
# File 'lib/byebug/commands/var/const.rb', line 32

def execute
  obj = single_thread_eval(str_obj)
  unless obj.is_a?(Module)
    return errmsg(pr('variable.errors.not_module', object: str_obj))
  end

  constants = single_thread_eval("#{str_obj}.constants")
  puts prv(constants.sort.map { |c| [c, obj.const_get(c)] }, 'constant')
end