Class: Byebug::VarCommand

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

Overview

Show variables and its values.

Constant Summary collapse

Subcommands =
[
  ['constant', 2, 'Show constants of an object'],
  ['global', 1, 'Show global variables'],
  ['instance', 1, 'Show instance variables of self or a specific object'],
  ['local', 1, 'Show local variables in current scope'],
  ['all', 1, 'Shows local, global and instance variables of self']
].map do |name, min, help|
  Subcmd.new(name, min, help)
end

Class Method Summary collapse

Instance Method Summary collapse

Methods included from VarFunctions

#var_all, #var_constant, #var_global, #var_instance, #var_list, #var_local

Methods inherited from Command

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

Methods included from StringFunctions

#camelize, #prettify

Methods included from FileFunctions

#get_line, #get_lines, #n_lines, #normalize

Methods included from ParseFunctions

#get_int, #parse_steps, #syntax_valid?

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



98
99
100
101
102
103
104
# File 'lib/byebug/commands/var.rb', line 98

def description
  prettify <<-EOD
    [v]ar

    Show variables and its values.
  EOD
end

.namesObject



94
95
96
# File 'lib/byebug/commands/var.rb', line 94

def names
  %w(var)
end

Instance Method Details

#executeObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/byebug/commands/var.rb', line 80

def execute
  return puts(self.class.help) unless @match[1]

  subcmd = Command.find(Subcommands, @match[1])
  return errmsg("Unknown var command #{@match[1]}\n") unless subcmd

  if @state.context
    send("var_#{subcmd.name}", @match[2])
  else
    errmsg "'var #{subcmd.name}' not available without a context.\n"
  end
end

#regexpObject



76
77
78
# File 'lib/byebug/commands/var.rb', line 76

def regexp
  /^\s* v(?:ar)? (?: \s+(\S+) (?:\s(\S+))? )? \s*$/x
end