deck 1.0.6 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/deck/game.rb CHANGED
@@ -6,11 +6,12 @@ class Game
6
6
  attr_reader :deck, :hands, :number_of_hands, :number_of_cards
7
7
 
8
8
 
9
- def initialize(hands = 3, cards = 3)
9
+ def initialize(p_hands = 3, p_cards = 3)
10
10
  @deck = Deck.new
11
- @number_of_hands = hands
12
- @number_of_cards = cards
13
- 1..@number_of_hands.to_i do |n|
11
+ @number_of_hands = p_hands
12
+ @number_of_cards = p_cards
13
+ @hands = []
14
+ @number_of_hands.to_i.times do
14
15
  @hands << Hand.new
15
16
  end
16
17
  end
@@ -21,12 +22,11 @@ class Game
21
22
 
22
23
  def deal(shuffle = true)
23
24
  deck.shuffle! if shuffle
24
- 1..@hands.size do |n|
25
- 1..@number_of_cards.to_i do |m|
26
- @hands[m] << deck.draw
25
+ (1..hands.size).each do |n|
26
+ number_of_cards.times do
27
+ hands[n-1] << deck.draw
27
28
  end
28
29
  end
29
30
  end
30
31
 
31
- alias :deal! :deal
32
32
  end
data/lib/deck/hand.rb CHANGED
@@ -7,7 +7,7 @@ class Hand < Deck
7
7
  end
8
8
 
9
9
  def inspect
10
- @cards.each{|e| e.to_s}
10
+ @cards.map{|e| e.to_s}
11
11
  end
12
12
 
13
13
  end
data/lib/deck/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Deck
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.8"
3
3
  end
data/test/game_test.rb CHANGED
@@ -7,15 +7,22 @@ class GameTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
 
10
- def deals_ok
10
+ def test_deals_ok
11
11
  game = Game.new(10,5)
12
+ game.deal
12
13
  assert_equal 10, game.hands.size
13
14
 
14
15
  (1..10).each do |n|
15
- assert_equal 5, game.hands[n].size
16
+ assert_equal 5, game.hands[n-1].size
16
17
  end
17
18
 
18
19
  assert_equal 2, game.deck.size
19
20
  end
20
21
 
22
+ def test_default_deal_works
23
+ game = Game.new
24
+ game.deal
25
+ assert_instance_of Game, game
26
+ end
27
+
21
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: