Class: Coin
- Inherits:
-
Object
- Object
- Coin
- Defined in:
- lib/cardtrick/coin.rb
Instance Method Summary collapse
-
#initialize(h = {}) ⇒ Coin
constructor
A new instance of Coin.
- #key ⇒ Object
- #last ⇒ Object
- #map(&b) ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(h = {}) ⇒ Coin
Returns a new instance of Coin.
3 4 5 6 7 |
# File 'lib/cardtrick/coin.rb', line 3 def initialize h={} @key = h.delete(:key) @h = h @last = @h.keys.sample end |
Instance Method Details
#key ⇒ Object
8 9 10 |
# File 'lib/cardtrick/coin.rb', line 8 def key @key end |
#last ⇒ Object
15 16 17 |
# File 'lib/cardtrick/coin.rb', line 15 def last @last end |
#map(&b) ⇒ Object
11 12 13 14 |
# File 'lib/cardtrick/coin.rb', line 11 def map &b @last = @h.keys.sample b.call(self) end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/cardtrick/coin.rb', line 21 def to_s %[Flipped #{key} and got #{value}.] end |
#value ⇒ Object
18 19 20 |
# File 'lib/cardtrick/coin.rb', line 18 def value @h[@last] end |