Module: Byebug::Helpers::VarHelper

Overview

Utilities for variable subcommands

Instance Method Summary collapse

Methods included from EvalHelper

#error_eval, #silent_eval, #single_thread_eval, #thread_safe_eval, #warning_eval

Instance Method Details

#var_argsObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/byebug/helpers/var.rb', line 40

def var_args
  args = context.frame.args
  return if args == [[:rest]]

  all_locals = context.frame.locals
  arg_values = args.map { |arg| arg[1] }

  locals = all_locals.select { |k, _| arg_values.include?(k) }
  puts prv(locals.keys.sort.map { |k| [k, locals[k]] }, 'instance')
end

#var_globalObject



19
20
21
22
23
24
25
# File 'lib/byebug/helpers/var.rb', line 19

def var_global
  globals = global_variables.reject do |v|
    [:$IGNORECASE, :$=, :$KCODE, :$-K, :$binding].include?(v)
  end

  var_list(globals)
end

#var_instance(str) ⇒ Object



27
28
29
30
31
# File 'lib/byebug/helpers/var.rb', line 27

def var_instance(str)
  obj = single_thread_eval(str || 'self')

  var_list(obj.instance_variables, obj.instance_eval { binding })
end

#var_list(ary, binding = context.frame._binding) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/byebug/helpers/var.rb', line 11

def var_list(ary, binding = context.frame._binding)
  vars = ary.sort.map do |name|
    [name, safe_inspect(silent_eval(name.to_s, binding))]
  end

  puts prv(vars, 'instance')
end

#var_localObject



33
34
35
36
37
38
# File 'lib/byebug/helpers/var.rb', line 33

def var_local
  locals = context.frame.locals
  cur_self = context.frame._self
  locals[:self] = cur_self unless cur_self.to_s == 'main'
  puts prv(locals.keys.sort.map { |k| [k, locals[k]] }, 'instance')
end