Class: Bridge::Deal

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeal

Returns a new instance of Deal.



5
6
7
8
9
10
11
12
13
# File 'lib/bridge/deal.rb', line 5

def initialize
  @hands = []
  @deck = Deck.new
  Direction.values.each do |dir|
    @hands[Direction.send(dir)] = Hand.new
  end
  deal!
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



28
29
30
31
32
33
34
# File 'lib/bridge/deal.rb', line 28

def method_missing(m, *args, &block)
  if hands.respond_to?(m)
    hands.send(m, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#deckObject

Returns the value of attribute deck.



3
4
5
# File 'lib/bridge/deal.rb', line 3

def deck
  @deck
end

#handsObject

Returns the value of attribute hands.



3
4
5
# File 'lib/bridge/deal.rb', line 3

def hands
  @hands
end

Class Method Details

.from_pageObject



24
25
26
# File 'lib/bridge/deal.rb', line 24

def self.from_page
  # create deal and hands based on HEX bridge book page number
end

Instance Method Details

#deal!Object

deals one card per hand on a cycle until we run out of cards



16
17
18
# File 'lib/bridge/deal.rb', line 16

def deal!
  hands.cycle(deck.size/hands.size) { |hand| hand << deck.shift }
end

#to_pageObject



20
21
22
# File 'lib/bridge/deal.rb', line 20

def to_page
  # returns HEX bridge book page value
end