Class: Coin

Inherits:
Object
  • Object
show all
Defined in:
lib/cardtrick/coin.rb

Instance Method Summary collapse

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

#keyObject



8
9
10
# File 'lib/cardtrick/coin.rb', line 8

def key
  @key
end

#lastObject



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_sObject



21
22
23
# File 'lib/cardtrick/coin.rb', line 21

def to_s
  %[Flipped #{key} and got #{value}.]
end

#valueObject



18
19
20
# File 'lib/cardtrick/coin.rb', line 18

def value
  @h[@last]
end