Module: Yzz::Side
- Included in:
- NegwardSide, PoswardSide
- Defined in:
- lib/yzz/side.rb
Overview
Ted Nelson calls objects in a ZZ structure ‘cells’ and defines that each cell has exactly two sides, posward side and negward side, along each dimension. This is represented by Yzz::Side
class here.
Instance Attribute Summary collapse
-
#neighbor ⇒ Object
readonly
Returns the value of attribute neighbor.
Instance Method Summary collapse
-
#crossover(new_neighbor) ⇒ Object
(also: #*)
Sets a new neighboor, crossing over the conflicting link, if present, with the old neighbor.
-
#dimension ⇒ Object
Reader #dimension delegates to the class, relying on parametrized subclassing.
-
#initialize(neighbor: nil) ⇒ Object
The constructor has one optional named parameter :neighbor.
-
#inspect ⇒ Object
Inspect string of the instance.
-
#link(new_neighbor) ⇒ Object
(also: #<<)
Links a new neighbor, unlinking and returning the old one.
-
#unlink ⇒ Object
Unlinks the neighbor, returning it.
-
#zz ⇒ Object
Reader #zz delegates to the class, relying on parametrized subclassing.
Instance Attribute Details
#neighbor ⇒ Object (readonly)
Returns the value of attribute neighbor.
6 7 8 |
# File 'lib/yzz/side.rb', line 6 def neighbor @neighbor end |
Instance Method Details
#crossover(new_neighbor) ⇒ Object Also known as: *
Sets a new neighboor, crossing over the conflicting link, if present, with the old neighbor.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/yzz/side.rb', line 46 def crossover new_neighbor return unlink if new_neighbor.nil? fail TypeError, "Zz object or nil expected!" unless new_neighbor.is_a_zz? conflicter = opposite_side( of: new_neighbor ).neighbor return new_neighbor if conflicter == self # no neighbor change begin # TODO: Should be an atomic transaction old_neighbor = set_neighbor! new_neighbor opposite_side( of: new_neighbor ).set_neighbor! zz same_side( of: conflicter ).set_neighbor! old_neighbor # cross over opposite_side( of: old_neighbor ).set_neighbor! conflicter # cross over end return old_neighbor end |
#dimension ⇒ Object
Reader #dimension delegates to the class, relying on parametrized subclassing.
15 |
# File 'lib/yzz/side.rb', line 15 def dimension; self.class.dimension end |
#initialize(neighbor: nil) ⇒ Object
The constructor has one optional named parameter :neighbor.
19 20 21 |
# File 'lib/yzz/side.rb', line 19 def initialize neighbor: nil set_neighbor! neighbor end |
#inspect ⇒ Object
Inspect string of the instance.
71 72 73 |
# File 'lib/yzz/side.rb', line 71 def inspect to_s end |
#link(new_neighbor) ⇒ Object Also known as: <<
Links a new neighbor, unlinking and returning the old one. Cares about the argument type (a Yzz descendant or nil), and cares not to break the new neighbor’s conflicting connectivity, if any.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/yzz/side.rb', line 27 def link new_neighbor return unlink if new_neighbor.nil? fail TypeError, "Yzz object or nil expected!" unless new_neighbor.is_a_zz? conflicter = opposite_side( of: new_neighbor ).neighbor # have concerns return new_neighbor if conflicter == self # no neighbor change fail TypeError, "Suggested new neighbor (#{new_neighbor}) already " + "has a conflicting #{opposite_direction} link along dimension " + "#{dimension}!" if conflicter.is_a_zz? begin # TODO: Should be an atomic transaction old_neighbor = set_neighbor! new_neighbor opposite_side( of: new_neighbor ).set_neighbor! zz end return old_neighbor end |
#unlink ⇒ Object
Unlinks the neighbor, returning it.
63 64 65 66 67 |
# File 'lib/yzz/side.rb', line 63 def unlink unlink!.tap do |neighbor| opposite_side( of: neighbor ).unlink! if neighbor.is_a_zz? end end |
#zz ⇒ Object
Reader #zz delegates to the class, relying on parametrized subclassing.
10 |
# File 'lib/yzz/side.rb', line 10 def zz; self.class.zz end |