module Byebug::VarFunctions

Utilities for the var command.

Public Instance Methods

var_all(_str = nil) click to toggle source
# File lib/byebug/commands/var.rb, line 53
def var_all(_str = nil)
  var_global
  var_instance('self')
  var_local
end
var_constant(str) click to toggle source
# File lib/byebug/commands/var.rb, line 37
def var_constant(str)
  str ||= 'self.class'
  obj = bb_warning_eval(str)
  is_mod = obj.is_a?(Module)
  return errmsg(pr('variable.errors.not_module', object: str)) unless is_mod

  constants = bb_eval("#{str}.constants")
  puts prv(constants.sort.map { |c| [c, obj.const_get(c)] })
end
var_global(_str = nil) click to toggle source
# File lib/byebug/commands/var.rb, line 24
def var_global(_str = nil)
  globals = global_variables.reject do |v|
    [:$IGNORECASE, :$=, :$KCODE, :$-K, :$binding].include?(v)
  end

  var_list(globals)
end
var_instance(str) click to toggle source
# File lib/byebug/commands/var.rb, line 32
def var_instance(str)
  obj = bb_warning_eval(str || 'self')
  var_list(obj.instance_variables, obj.instance_eval { binding })
end
var_list(ary, b = get_binding) click to toggle source
# File lib/byebug/commands/var.rb, line 8
def var_list(ary, b = get_binding)
  vars = ary.sort.map do |v|
    s = begin
      b.eval(v.to_s).inspect
    rescue
      begin
        b.eval(v.to_s).to_s
      rescue
        '*Error in evaluation*'
      end
    end
    [v, s]
  end
  puts prv(vars)
end
var_local(_str = nil) click to toggle source
# File lib/byebug/commands/var.rb, line 47
def var_local(_str = nil)
  _self = @state.context.frame_self(@state.frame)
  locals = @state.context.frame_locals
  puts prv(locals.keys.sort.map { |k| [k, locals[k]] })
end