Class: Bridge::Deck

Inherits:
Object
  • Object
show all
Defined in:
lib/bridge/deck.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeck

Returns a new instance of Deck.



7
8
9
10
# File 'lib/bridge/deck.rb', line 7

def initialize
  @cards = Card::RANKS.product(Card::SUITS).map { |a| Card.new(a[0],a[1]) }
  @cards.shuffle!(random: SecureRandom)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/bridge/deck.rb', line 25

def method_missing(method, *args, &block)
  begin
    @cards.send(method, *args, &block)
  rescue Exception => e
    super
  end
end

Instance Attribute Details

#cardsObject

Returns the value of attribute cards.



5
6
7
# File 'lib/bridge/deck.rb', line 5

def cards
  @cards
end

Instance Method Details

#inspectObject



21
22
23
# File 'lib/bridge/deck.rb', line 21

def inspect
  cards.inspect
end

#shuffleObject



17
18
19
# File 'lib/bridge/deck.rb', line 17

def shuffle
  @cards.shuffle(random: SecureRandom)
end

#shuffle!Object

make sure shuffling is as random as possible



13
14
15
# File 'lib/bridge/deck.rb', line 13

def shuffle!
  @cards.shuffle!(random: SecureRandom)
end