Class: Stupidedi::Zipper::Hole
- Inherits:
-
AbstractPath
- Object
- AbstractPath
- Stupidedi::Zipper::Hole
- Defined in:
- lib/stupidedi/zipper/path.rb
Instance Attribute Summary collapse
-
#left ⇒ Array<#leaf?, #children, #copy>
readonly
Contains the node’s rightward siblings, sorted nearest to furthest.
- #parent ⇒ AbstractPath readonly
-
#right ⇒ Array<#leaf?, #children, #copy>
readonly
Contains the node’s leftward siblings, sorted nearest to furthest.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#depth ⇒ Integer
Distance from the root node.
- #first? ⇒ Boolean
-
#initialize(left, parent, right) ⇒ Hole
constructor
A new instance of Hole.
- #inspect ⇒ String
- #last? ⇒ Boolean
- #position ⇒ Object
Constructor Details
#initialize(left, parent, right) ⇒ Hole
Returns a new instance of Hole.
89 90 91 92 |
# File 'lib/stupidedi/zipper/path.rb', line 89 def initialize(left, parent, right) @left, @parent, @right = left, parent, right end |
Instance Attribute Details
#left ⇒ Array<#leaf?, #children, #copy> (readonly)
Contains the node’s rightward siblings, sorted nearest to furthest
81 82 83 |
# File 'lib/stupidedi/zipper/path.rb', line 81 def left @left end |
#parent ⇒ AbstractPath (readonly)
84 85 86 |
# File 'lib/stupidedi/zipper/path.rb', line 84 def parent @parent end |
#right ⇒ Array<#leaf?, #children, #copy> (readonly)
Contains the node’s leftward siblings, sorted nearest to furthest
87 88 89 |
# File 'lib/stupidedi/zipper/path.rb', line 87 def right @right end |
Instance Method Details
#==(other) ⇒ Boolean
119 120 121 122 |
# File 'lib/stupidedi/zipper/path.rb', line 119 def ==(other) depth == other.depth and position == other.position end |
#depth ⇒ Integer
Distance from the root node
105 106 107 |
# File 'lib/stupidedi/zipper/path.rb', line 105 def depth 1 + @parent.depth end |
#first? ⇒ Boolean
100 101 102 |
# File 'lib/stupidedi/zipper/path.rb', line 100 def first? @left.empty? end |
#inspect ⇒ String
114 115 116 |
# File 'lib/stupidedi/zipper/path.rb', line 114 def inspect "#{@parent.inspect}/#{@left.length}" end |
#last? ⇒ Boolean
95 96 97 |
# File 'lib/stupidedi/zipper/path.rb', line 95 def last? @right.empty? end |
#position ⇒ Object
109 110 111 |
# File 'lib/stupidedi/zipper/path.rb', line 109 def position @left.length end |