Class: Bridge::Trick
- Inherits:
-
Object
- Object
- Bridge::Trick
- Defined in:
- lib/bridge/trick.rb
Constant Summary collapse
- REQUIRED_CARDS =
4
Instance Attribute Summary collapse
-
#cards ⇒ Object
Returns the value of attribute cards.
-
#leader ⇒ Object
Returns the value of attribute leader.
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(params = {}) ⇒ Trick
constructor
A new instance of Trick.
- #leader_card ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Trick
Returns a new instance of Trick.
6 7 8 9 |
# File 'lib/bridge/trick.rb', line 6 def initialize(params = {}) params.map { |k,v| self.send(:"#{k}=",v) } self.cards = [] if self.cards.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/bridge/trick.rb', line 19 def method_missing(method, *args, &block) begin self.cards = self.cards.to_s.split(' ').map { |c| Card.from_string(c) } unless self.cards.class == Array self.cards.send(method, *args, &block) rescue Exception => e super end end |
Instance Attribute Details
#cards ⇒ Object
Returns the value of attribute cards.
4 5 6 |
# File 'lib/bridge/trick.rb', line 4 def cards @cards end |
#leader ⇒ Object
Returns the value of attribute leader.
5 6 7 |
# File 'lib/bridge/trick.rb', line 5 def leader @leader end |
Instance Method Details
#done? ⇒ Boolean
11 12 13 |
# File 'lib/bridge/trick.rb', line 11 def done? self.cards.compact.size >= REQUIRED_CARDS end |
#leader_card ⇒ Object
15 16 17 |
# File 'lib/bridge/trick.rb', line 15 def leader_card self.cards[self.leader] end |