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.
87 88 89 90 |
# File 'lib/stupidedi/zipper/path.rb', line 87 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
79 80 81 |
# File 'lib/stupidedi/zipper/path.rb', line 79 def left @left end |
#parent ⇒ AbstractPath (readonly)
82 83 84 |
# File 'lib/stupidedi/zipper/path.rb', line 82 def parent @parent end |
#right ⇒ Array<#leaf?, #children, #copy> (readonly)
Contains the node’s leftward siblings, sorted nearest to furthest
85 86 87 |
# File 'lib/stupidedi/zipper/path.rb', line 85 def right @right end |
Instance Method Details
#==(other) ⇒ Boolean
117 118 119 120 |
# File 'lib/stupidedi/zipper/path.rb', line 117 def ==(other) depth == other.depth and position == other.position end |
#depth ⇒ Integer
Distance from the root node
103 104 105 |
# File 'lib/stupidedi/zipper/path.rb', line 103 def depth 1 + @parent.depth end |
#first? ⇒ Boolean
98 99 100 |
# File 'lib/stupidedi/zipper/path.rb', line 98 def first? @left.empty? end |
#inspect ⇒ String
112 113 114 |
# File 'lib/stupidedi/zipper/path.rb', line 112 def inspect "#{@parent.inspect}/#{@left.length}" end |
#last? ⇒ Boolean
93 94 95 |
# File 'lib/stupidedi/zipper/path.rb', line 93 def last? @right.empty? end |
#position ⇒ Object
107 108 109 |
# File 'lib/stupidedi/zipper/path.rb', line 107 def position @left.length end |