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
True when the node has no leftward siblings.
-
#initialize(left, parent, right) ⇒ Hole
constructor
A new instance of Hole.
- #inspect ⇒ String
-
#last? ⇒ Boolean
True when the node has no rightward siblings.
- #position
- #root? ⇒ Boolean
Constructor Details
#initialize(left, parent, right) ⇒ Hole
Returns a new instance of Hole.
92 93 94 95 |
# File 'lib/stupidedi/zipper/path.rb', line 92 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
84 85 86 |
# File 'lib/stupidedi/zipper/path.rb', line 84 def left @left end |
#parent ⇒ AbstractPath (readonly)
87 88 89 |
# File 'lib/stupidedi/zipper/path.rb', line 87 def parent @parent end |
#right ⇒ Array<#leaf?, #children, #copy> (readonly)
Contains the node's leftward siblings, sorted nearest to furthest
90 91 92 |
# File 'lib/stupidedi/zipper/path.rb', line 90 def right @right end |
Instance Method Details
#==(other) ⇒ Boolean
126 127 128 129 |
# File 'lib/stupidedi/zipper/path.rb', line 126 def ==(other) depth == other.depth and position == other.position end |
#depth ⇒ Integer
Distance from the root node
112 113 114 |
# File 'lib/stupidedi/zipper/path.rb', line 112 def depth 1 + @parent.depth end |
#first? ⇒ Boolean
True when the node has no leftward siblings
107 108 109 |
# File 'lib/stupidedi/zipper/path.rb', line 107 def first? @left.empty? end |
#inspect ⇒ String
121 122 123 |
# File 'lib/stupidedi/zipper/path.rb', line 121 def inspect "#{@parent.inspect}/#{@left.length}" end |
#last? ⇒ Boolean
True when the node has no rightward siblings
102 103 104 |
# File 'lib/stupidedi/zipper/path.rb', line 102 def last? @right.empty? end |
#position
116 117 118 |
# File 'lib/stupidedi/zipper/path.rb', line 116 def position @left.length end |
#root? ⇒ Boolean
97 98 99 |
# File 'lib/stupidedi/zipper/path.rb', line 97 def root? false end |