Class: GlimmerKlondikeSolitaire::Model::FoundationPile
- Inherits:
-
Object
- Object
- GlimmerKlondikeSolitaire::Model::FoundationPile
- Defined in:
- app/glimmer_klondike_solitaire/model/foundation_pile.rb
Instance Attribute Summary collapse
-
#suit ⇒ Object
readonly
Returns the value of attribute suit.
Instance Method Summary collapse
-
#add!(playing_card) ⇒ Object
adds a card validates if it is a card that belongs to the suit.
-
#initialize(game, suit) ⇒ FoundationPile
constructor
A new instance of FoundationPile.
- #playing_cards ⇒ Object
- #reset! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(game, suit) ⇒ FoundationPile
Returns a new instance of FoundationPile.
6 7 8 9 10 |
# File 'app/glimmer_klondike_solitaire/model/foundation_pile.rb', line 6 def initialize(game, suit) @game = game @suit = suit reset! end |
Instance Attribute Details
#suit ⇒ Object (readonly)
Returns the value of attribute suit.
4 5 6 |
# File 'app/glimmer_klondike_solitaire/model/foundation_pile.rb', line 4 def suit @suit end |
Instance Method Details
#add!(playing_card) ⇒ Object
adds a card validates if it is a card that belongs to the suit
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/glimmer_klondike_solitaire/model/foundation_pile.rb', line 18 def add!() if .suit == suit && ( (.empty? && .rank == 1) || .rank == (.last.rank + 1) ) .push() else raise "Cannot add #{} to #{self}" end end |
#playing_cards ⇒ Object
30 31 32 |
# File 'app/glimmer_klondike_solitaire/model/foundation_pile.rb', line 30 def @playing_cards ||= [] end |
#reset! ⇒ Object
12 13 14 |
# File 'app/glimmer_klondike_solitaire/model/foundation_pile.rb', line 12 def reset! .clear end |
#to_s ⇒ Object
34 35 36 |
# File 'app/glimmer_klondike_solitaire/model/foundation_pile.rb', line 34 def to_s "Foundation Pile #{suit} (#{.map {|card| "#{card.rank}#{card.suit.to_s[0].upcase}"}.join(" | ")})" end |