Class: RubyBreaker::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/rubybreaker/debug/context.rb

Overview

This class represents a context which consists of one or more positions. A position can refer to a physical file/line position or a virtual position with respect to an object. A context is commonly used to represent a chain of positions for types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pos) ⇒ Context

Returns a new instance of Context.



81
82
83
84
# File 'lib/rubybreaker/debug/context.rb', line 81

def initialize(pos)
  @pos = pos
  @child = nil
end

Instance Attribute Details

#childObject

Returns the value of attribute child.



79
80
81
# File 'lib/rubybreaker/debug/context.rb', line 79

def child
  @child
end

#posObject

location is either Position or ObjectPosition



78
79
80
# File 'lib/rubybreaker/debug/context.rb', line 78

def pos
  @pos
end

Instance Method Details

#format_with_msg(pp, msg = "") ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rubybreaker/debug/context.rb', line 104

def format_with_msg(pp,msg="")
  pp.text(@pos.to_s)
  pp.breakable()
  if @child
    pp.group(2) { 
      pp.breakable()
      @child.format_with_msg(pp,msg)
    }
  elsif msg != ""
    pp.group(2) do
      pp.breakable()
      pp.text("> #{msg}",79)
    end
  end
end

#popObject



94
95
96
97
98
99
100
101
102
# File 'lib/rubybreaker/debug/context.rb', line 94

def pop
  if @child && @child.child
    @child.pop
  elsif @child
    @child = nil
  else 
    # root; don't do anything
  end
end

#push(pos) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/rubybreaker/debug/context.rb', line 86

def push(pos)
  if @child 
    @child.push(pos)
  else
    @child = Context.new(pos)
  end
end