class GlimmerKlondikeSolitaire::Model::FoundationPile
Attributes
suit[R]
Public Class Methods
new(game, suit)
click to toggle source
# File app/glimmer_klondike_solitaire/model/foundation_pile.rb, line 6 def initialize(game, suit) @game = game @suit = suit reset! end
Public Instance Methods
add!(playing_card)
click to toggle source
adds a card validates if it is a card that belongs to the suit
# File app/glimmer_klondike_solitaire/model/foundation_pile.rb, line 18 def add!(playing_card) if playing_card.suit == suit && ( (playing_cards.empty? && playing_card.rank == 1) || playing_card.rank == (playing_cards.last.rank + 1) ) playing_cards.push(playing_card) else raise "Cannot add #{playing_card} to #{self}" end end
playing_cards()
click to toggle source
# File app/glimmer_klondike_solitaire/model/foundation_pile.rb, line 30 def playing_cards @playing_cards ||= [] end
reset!()
click to toggle source
# File app/glimmer_klondike_solitaire/model/foundation_pile.rb, line 12 def reset! playing_cards.clear end
to_s()
click to toggle source
# File app/glimmer_klondike_solitaire/model/foundation_pile.rb, line 34 def to_s "Foundation Pile #{suit} (#{playing_cards.map {|card| "#{card.rank}#{card.suit.to_s[0].upcase}"}.join(" | ")})" end