Class: Stupidedi::Zipper::Hole

Inherits:
AbstractPath show all
Defined in:
lib/stupidedi/zipper/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, parent, right) ⇒ Hole

Returns a new instance of Hole.



97
98
99
100
# File 'lib/stupidedi/zipper/path.rb', line 97

def initialize(left, parent, right)
  @left, @parent, @right =
    left, parent, right
end

Instance Attribute Details

#leftArray<#leaf?, #children, #copy> (readonly)

Contains the node’s rightward siblings, sorted nearest to furthest

Returns:

  • (Array<#leaf?, #children, #copy>)


89
90
91
# File 'lib/stupidedi/zipper/path.rb', line 89

def left
  @left
end

#parentAbstractPath (readonly)

Returns:



92
93
94
# File 'lib/stupidedi/zipper/path.rb', line 92

def parent
  @parent
end

#rightArray<#leaf?, #children, #copy> (readonly)

Contains the node’s leftward siblings, sorted nearest to furthest

Returns:

  • (Array<#leaf?, #children, #copy>)


95
96
97
# File 'lib/stupidedi/zipper/path.rb', line 95

def right
  @right
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
134
# File 'lib/stupidedi/zipper/path.rb', line 131

def ==(other)
  depth    == other.depth and
  position == other.position
end

#depthInteger

Distance from the root node

Returns:



117
118
119
# File 'lib/stupidedi/zipper/path.rb', line 117

def depth
  1 + @parent.depth
end

#first?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/stupidedi/zipper/path.rb', line 112

def first?
  @left.empty?
end

#inspectString

Returns:



126
127
128
# File 'lib/stupidedi/zipper/path.rb', line 126

def inspect
  "#{@parent.inspect}/#{@left.length}"
end

#last?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/stupidedi/zipper/path.rb', line 107

def last?
  @right.empty?
end

#positionObject



121
122
123
# File 'lib/stupidedi/zipper/path.rb', line 121

def position
  @left.length
end

#root?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/stupidedi/zipper/path.rb', line 102

def root?
  false
end