Module: FiftyTwo::HasCards
Constant Summary collapse
Class.new(StandardError)
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Instance Method Summary collapse
- #draw ⇒ Object
- #initialize(cards = []) ⇒ Object
- #locate(identifier) ⇒ Object
- #render ⇒ Object
- #transfer(cards, destination = nil) ⇒ Object
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
6 7 8 |
# File 'lib/fiftytwo/has_cards.rb', line 6 def cards @cards end |
Instance Method Details
#draw ⇒ Object
15 16 17 |
# File 'lib/fiftytwo/has_cards.rb', line 15 def draw cards.shift end |
#initialize(cards = []) ⇒ Object
11 12 13 |
# File 'lib/fiftytwo/has_cards.rb', line 11 def initialize(cards = []) @cards = cards end |
#locate(identifier) ⇒ Object
23 24 25 26 |
# File 'lib/fiftytwo/has_cards.rb', line 23 def locate(identifier) return cards[identifier] if identifier.is_a?(Integer) cards.find { |c| c.identifier == identifier.upcase } end |
#render ⇒ Object
19 20 21 |
# File 'lib/fiftytwo/has_cards.rb', line 19 def render map(&:render).join(" ") end |
#transfer(cards, destination = nil) ⇒ Object
28 29 30 |
# File 'lib/fiftytwo/has_cards.rb', line 28 def transfer(cards, destination = nil) gather(cards).map { |c| (destination || c.deck) << self.cards.delete(c) } end |