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.



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

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

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

Returns:

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


81
82
83
# File 'lib/stupidedi/zipper/path.rb', line 81

def left
  @left
end

#parentAbstractPath (readonly)

Returns:



84
85
86
# File 'lib/stupidedi/zipper/path.rb', line 84

def parent
  @parent
end

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

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

Returns:

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


87
88
89
# File 'lib/stupidedi/zipper/path.rb', line 87

def right
  @right
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#depthInteger

Distance from the root node

Returns:

  • (Integer)


105
106
107
# File 'lib/stupidedi/zipper/path.rb', line 105

def depth
  1 + @parent.depth
end

#first?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/stupidedi/zipper/path.rb', line 100

def first?
  @left.empty?
end

#inspectString

Returns:

  • (String)


114
115
116
# File 'lib/stupidedi/zipper/path.rb', line 114

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

#last?Boolean

Returns:

  • (Boolean)


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

def last?
  @right.empty?
end

#positionObject



109
110
111
# File 'lib/stupidedi/zipper/path.rb', line 109

def position
  @left.length
end