Class: Gambit::Tools::Cards::Hand

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Viewable
Defined in:
lib/gambit/tools/cards/hand.rb

Overview

An object for managing a Hand of cards.

Instance Method Summary collapse

Methods included from Viewable

append_features, #view

Constructor Details

#initializeHand

Create an empty Hand of cards.



36
37
38
# File 'lib/gambit/tools/cards/hand.rb', line 36

def initialize(  )
	@hand   = Array.new
end

Instance Method Details

#<<(card) ⇒ Object

Add a card to this Hand.

Returns self for method chaining.



50
51
52
53
54
# File 'lib/gambit/tools/cards/hand.rb', line 50

def <<( card )
	@hand << card
	
	self
end

#[](index) ⇒ Object

Fetch a card by index.



41
42
43
# File 'lib/gambit/tools/cards/hand.rb', line 41

def []( index )
	@hand[index]
end

#countObject

Returns the Hand size.



57
58
59
# File 'lib/gambit/tools/cards/hand.rb', line 57

def count(  )
	@hand.size
end

#discard(index) ⇒ Object

Removes and returns the card at the given index.



69
70
71
# File 'lib/gambit/tools/cards/hand.rb', line 69

def discard( index )
	@hand.delete_at(index)
end

#each(&block) ⇒ Object

Iterate through the cards.



64
65
66
# File 'lib/gambit/tools/cards/hand.rb', line 64

def each( &block )
	@hand.each(&block)
end

#sort!(&block) ⇒ Object

Sort the Hand by card value.

Returns self for method chaining.



78
79
80
81
82
# File 'lib/gambit/tools/cards/hand.rb', line 78

def sort!( &block )
	@hand.sort!(&block)
	
	self
end