Module: Doku::DancingLinks::HorizontalLinks

Includes:
Uninspectable
Included in:
LinkMatrix, LinkMatrix::Column, LinkMatrix::Node
Defined in:
lib/doku/dancing_links.rb

Overview

This module is mixed into objects to give them their “left” and “right” links, and to give some convenient methods for changing those links. Every class this module is added to gains to attr_accessors: left and right.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Uninspectable

#inspect

Class Method Details

.included(klass) ⇒ Object



68
69
70
71
72
# File 'lib/doku/dancing_links.rb', line 68

def self.included(klass)
  klass.instance_eval do
    attr_accessor :left, :right
  end
end

Instance Method Details

#insert_left(obj) ⇒ Object

Inserts this object to the left of the specified object in the horizontal list.



92
93
94
95
# File 'lib/doku/dancing_links.rb', line 92

def insert_left(obj)
  self.left, self.right = obj.left, obj
  reinsert_horizontal
end

#reinsert_horizontalObject

Reinserts this object into the horizontal linked list by making the former left and right neighors point to this object instead of each other. The former left and right neighbors are simply found by looking at the “left” and “right” links for this object, which still point to them. This undoes the effect of #remove_horizontal.



86
87
88
# File 'lib/doku/dancing_links.rb', line 86

def reinsert_horizontal
  left.right = right.left = self
end

#remove_horizontalObject

Removes this object from the horizontal linked list by making the left and right neighbors point at each other instead of this object. This can later be undone with #reinsert_horizontal



77
78
79
# File 'lib/doku/dancing_links.rb', line 77

def remove_horizontal
  right.left, left.right = left, right
end