Class: Byebug::VarConstantCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/byebug/commands/variables.rb

Overview

Show constants and its values.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



130
131
132
# File 'lib/byebug/commands/variables.rb', line 130

def description
  %(v[ar] co[nst] <object>        Show constants of <object>.)
end

.namesObject



126
127
128
# File 'lib/byebug/commands/variables.rb', line 126

def names
  %w(var)
end

Instance Method Details

#executeObject



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/byebug/commands/variables.rb', line 111

def execute
  obj = bb_eval(@match.post_match)
  if obj.is_a? Module
    constants = bb_eval("#{@match.post_match}.constants")
    constants.sort!
    constants.each do |c|
      value = obj.const_get(c)
      puts format(' %s => %p', c, value)
    end
  else
    puts "Should be Class/Module: #{@match.post_match}"
  end
end

#regexpObject



107
108
109
# File 'lib/byebug/commands/variables.rb', line 107

def regexp
  /^\s* v(?:ar)? \s+ co(?:nst(?:ant)?)? \s+/x
end