module Cardname::Pieces

Cards never have more than two “parts” (left and right), but they can have many “pieces”. A card's pieces are all the other cards whose existence its existence implies. For example if A+B+C exists, that implies that A, B, C, and A+B do too.

Public Instance Methods

pieces() click to toggle source

self and all ancestors (= parts and recursive lefts) @example

"A+B+C+D".to_name.pieces
# => ["A", "B", "C", "D", "A+B", "A+B+C", "A+B+C+D"]
# File lib/cardname/pieces.rb, line 10
def pieces
  @pieces ||= simple? ? [self] : (parts + junction_pieces)
end

Private Instance Methods

junction_pieces() click to toggle source
# File lib/cardname/pieces.rb, line 16
def junction_pieces
  [].tap do |pieces|
    parts[1..-1].inject parts[0] do |left, right|
      piece = [left, right] * self.class.joint
      pieces << piece
      piece
    end
  end
end