Class: TwentyOne::Chip

Inherits:
Object
  • Object
show all
Defined in:
lib/twenty_one/chip.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color) ⇒ Chip

Returns a new instance of Chip.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/twenty_one/chip.rb', line 5

def initialize(color)
	@color = color

	case color
	when :white
		@value = 1
	when :red
		@value = 5
	when :green
		@value = 25 
	when :black
		@value = 100
	end
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



3
4
5
# File 'lib/twenty_one/chip.rb', line 3

def color
  @color
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/twenty_one/chip.rb', line 3

def value
  @value
end

Class Method Details

.generate_chips(color, total) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/twenty_one/chip.rb', line 20

def self.generate_chips(color, total)
	set  = []

	total.times do
		set.push Chip.new(color)	
	end

	set
end

.get_amount(chips) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/twenty_one/chip.rb', line 30

def self.get_amount(chips)
	amount = 0

	chips.each do |chip|
		amount += chip.value
	end

	amount
end