class Doku::DancingLinks::LinkEnumerator
This is a class that lets us concisely enumerate a certain set of objects by traveling either up, down, left, or right from a starting object until we wrap around and reach that same node. Since this class includes the Enumerable class, it has several fancy methods available with it such as “max_by”, “collect”, or “to_a”.
Public Class Methods
@param link (Symbol) The link to follow. Should be :up, :down, :left, or :right. @param start (Object) The starting object. Typically a {LinkMatrix::Node}, {LinkMatrix::Column} (column header), or {LinkMatrix} (root node). @param include_start (Boolean) True if we want to include the starting object in this enumeration.
# File lib/doku/dancing_links.rb, line 38 def initialize(link, start, include_start=false) @link, @start, @include_start = link, start, include_start end
Public Instance Methods
Iterates through objects by starting at the starting object and going in the specified direction until the start point is found again. The starting object will be yielded first, if this LinkEnumerator
was configured to yield it {#initialize}. @yield (obj)
# File lib/doku/dancing_links.rb, line 48 def each yield @start if @include_start n = @start while true n = n.send @link return if n == @start yield n end end