Class: Card
- Inherits:
-
Object
- Object
- Card
- Defined in:
- lib/99_game.rb
Overview
Represents a card in the deck
Constant Summary collapse
- @@value =
{"Ace" => 1, 4 => 0, 9 => 0, "Jack" => 0, "Joker" => 0, "King" => 99, "Queen" => -10}
Instance Attribute Summary collapse
-
#num ⇒ Object
readonly
Returns the value of attribute num.
Instance Method Summary collapse
-
#_value ⇒ Object
Backup method for Card#value.
-
#initialize(card) ⇒ Card
constructor
Creates a new card.
-
#value ⇒ Object
Gives the Card’s value.
Constructor Details
#initialize(card) ⇒ Card
Creates a new card
47 |
# File 'lib/99_game.rb', line 47 def initialize(card); @num = card; end |
Instance Attribute Details
#num ⇒ Object (readonly)
Returns the value of attribute num.
24 25 26 |
# File 'lib/99_game.rb', line 24 def num @num end |
Instance Method Details
#_value ⇒ Object
Backup method for Card#value
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/99_game.rb', line 32 def _value return case @num when "Ace" then 1 when 2..3 then @num when 4 then 0 when 5..8 then @num when 9 then 0 when 10 then 10 when "Jack" then 0 when "Queen" then -10 when "King" then 99 when "Joker" then 0 end end |
#value ⇒ Object
Gives the Card’s value
27 28 29 30 |
# File 'lib/99_game.rb', line 27 def value @@value.default = @num.to_i return @@value[@num] end |