Class: RShade::StackFrame

Inherits:
Object show all
Defined in:
lib/rshade/stack_frame.rb

Overview

nodoc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ StackFrame

Returns a new instance of StackFrame.



8
9
10
# File 'lib/rshade/stack_frame.rb', line 8

def initialize(hash)
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



6
7
8
# File 'lib/rshade/stack_frame.rb', line 6

def hash
  @hash
end

Class Method Details

.from_binding(binding_frame) ⇒ Object

Parameters:

  • binding_frame (Binding)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rshade/stack_frame.rb', line 23

def self.from_binding(binding_frame)
  source_location = {
    path: binding_frame.source_location[0],
    line: binding_frame.source_location[1]
  }
  local_vars = binding_frame.local_variables.each_with_object({}) do |var_name, memo|
    value = binding_frame.local_variable_get(var_name)
    type = value.is_a?(Class) ? value : value.class
    memo[var_name] = {
      name: var_name,
      value: value,
      type: type.to_s
    }
  end
  receiver_variables = binding_frame.receiver.instance_variables.each_with_object({}) do |var_name, memo|
    value = binding_frame.receiver.instance_variable_get(var_name)
    type = value.is_a?(Class) ? value : value.class
    memo[var_name] = {
      name: var_name,
      value: value,
      type: type.to_s
    }
  end
  hash = { source_location: source_location, local_vars: local_vars, source: {},
           receiver_variables: receiver_variables }
  new(hash)
end

Instance Method Details

#pathObject



18
19
20
# File 'lib/rshade/stack_frame.rb', line 18

def path
  source_location[:path]
end

#to_sObject



51
52
53
# File 'lib/rshade/stack_frame.rb', line 51

def to_s
  "#{source_location} - #{local_vars} - #{source}"
end