Top Level Namespace
Defined Under Namespace
Instance Method Summary collapse
- #card_test(card, actual_value) ⇒ Integer
-
#converter(input) ⇒ String, Integer
If parameter input is an abbreviation, input is converted to what it stands for.
-
#not_nil?(obj) ⇒ Boolean
Tests if obj is not nil.
-
#pause(p) ⇒ void
Combines sleep and a newline.
Instance Method Details
#card_test(card, actual_value) ⇒ Integer
Note:
Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/99_game.rb', line 10 def card_test(card, actual_value) test_value = case card.num when "King" then 99 when "Joker" then 0 else actual_value + card.value end test_value = -1 if test_value > 99 test_value end |
#converter(input) ⇒ String, Integer
If parameter input is an abbreviation, input is converted to what it stands for. Otherwise, it simply returns a capitalized version of input.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/99_game.rb', line 43 def converter(input) abbrev = {"$" => "Joker", "K" => "King", "J" => "Jack", "Q" => "Queen", "A" => "Ace"} raise(CardError, "Input cannot be blank") if input == String.new if input.to_i.zero? case input.capitalize when ?$, "Joker" then "Joker" when ?K, "King" then "King" when ?J, "Jack" then "Jack" when ?Q, "Queen" then "Queen" when ?A, "Ace" then "Ace" end else input.to_i end end |
#not_nil?(obj) ⇒ Boolean
Tests if obj is not nil.
21 22 23 |
# File 'lib/99_game.rb', line 21 def not_nil?(obj) !obj.nil? end |
#pause(p) ⇒ void
This method returns an undefined value.
Combines sleep and a newline
32 33 34 35 |
# File 'lib/99_game.rb', line 32 def pause(p) sleep p puts end |