Class: Bridge::Deal

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

Overview

deal, not game bidding create the contract bidding is also persistent bidding finishes after 3 passes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeal

Returns a new instance of Deal.



10
11
12
13
14
15
16
17
18
# File 'lib/bridge/deal.rb', line 10

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



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

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.



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

def deck
  @deck
end

#handsObject

Returns the value of attribute hands.



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

def hands
  @hands
end

Instance Method Details

#deal!Object

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



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

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