module Yzz::Side

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.

Attributes

neighbor[R]

Public Class Methods

new(neighbor: nil) click to toggle source

The constructor has one optional named parameter :neighbor.

# File lib/yzz/side.rb, line 19
def initialize neighbor: nil
  set_neighbor! neighbor
end

Public Instance Methods

*(new_neighbor)
Alias for: crossover
<<(new_neighbor)
Alias for: link
crossover(new_neighbor) click to toggle source

Sets a new neighboor, crossing over the conflicting link, if present, with the old neighbor.

# 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
Also aliased as: *
dimension() click to toggle source

Reader dimension delegates to the class, relying on parametrized subclassing.

# File lib/yzz/side.rb, line 15
def dimension; self.class.dimension end
inspect() click to toggle source

Inspect string of the instance.

# File lib/yzz/side.rb, line 71
def inspect
  to_s
end
zz() click to toggle source

Reader zz delegates to the class, relying on parametrized subclassing.

# File lib/yzz/side.rb, line 10
def zz; self.class.zz end

Protected Instance Methods

set_neighbor!(new_neighbor) click to toggle source

Sets neighbor carelessly, returning the old neighbor.

# File lib/yzz/side.rb, line 79
def set_neighbor! new_neighbor
  neighbor.tap { @neighbor = new_neighbor }
end