Module: Byebug::VarFunctions

Defined in:
lib/byebug/commands/variables.rb

Overview

Utilities for the var command.

Instance Method Summary collapse

Instance Method Details

#var_class_selfObject



24
25
26
27
# File 'lib/byebug/commands/variables.rb', line 24

def var_class_self
  obj = bb_eval('self')
  var_list(obj.class.class_variables, get_binding)
end

#var_globalObject



29
30
31
32
33
34
35
# File 'lib/byebug/commands/variables.rb', line 29

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

  var_list(globals)
end

#var_instance(where) ⇒ Object



37
38
39
40
# File 'lib/byebug/commands/variables.rb', line 37

def var_instance(where)
  obj = bb_eval(where)
  var_list(obj.instance_variables, obj.instance_eval { binding })
end

#var_list(ary, b = get_binding) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/byebug/commands/variables.rb', line 6

def var_list(ary, b = get_binding)
  ary.sort!
  ary.each do |v|
    begin
      s = bb_eval(v.to_s, b).inspect
    rescue
      begin
        s = bb_eval(v.to_s, b).to_s
      rescue
        s = '*Error in evaluation*'
      end
    end
    s = "#{v} = #{s}"
    s[Setting[:width] - 3..-1] = '...' if s.size > Setting[:width]
    puts s
  end
end

#var_localObject



42
43
44
45
46
47
48
# File 'lib/byebug/commands/variables.rb', line 42

def var_local
  _self = @state.context.frame_self(@state.frame_pos)
  locals = @state.context.frame_locals
  locals.keys.sort.each do |name|
    puts format('  %s => %p', name, locals[name])
  end
end