ruby-poker 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 2009-01-24 (0.3.1)
2
+ * Bug [#23623] undefined method <=> for nil:NilClass
3
+
4
+ 2008-12-30 (0.3.1)
5
+ * Bug (#20407) Raise an exception when creating a new hand with duplicates
6
+ * Added PokerHand#uniq method
7
+ * Removed deprecated `Gem::manage_gems` from Rakefile
8
+
1
9
  2008-05-17 (0.3.0)
2
10
  * Changed Card#== to compare based on card suit and face value. Before it only compared the face value of two cards. Warning: This change may potentially break your program if you were comparing Card objects directly.
3
11
  * Replaced `PokerHand#arranged_hand` with `PokerHand#sort_using_rank` which is more descriptive. This loosely corresponds to bug #20194.
data/README.rdoc ADDED
@@ -0,0 +1,51 @@
1
+ = Poker library in Ruby
2
+
3
+ == Author
4
+
5
+ Rob Olson (rko618 [at] gmail)
6
+
7
+ == Description
8
+
9
+ Ruby-Poker handles the logic for getting the rank of a poker hand. It can also be used to compare two or more hands to determine which hand has the highest poker value.
10
+
11
+ Card representations can be passed to the PokerHand constructor as a string or an array. Face cards (cards ten, jack, queen, king, and ace) are created using their letter representation (T, J, Q, K, A).
12
+
13
+ == Install
14
+
15
+ sudo gem install ruby-poker
16
+
17
+ == Examples
18
+
19
+ In this section some examples show what can be done with this class.
20
+
21
+ require 'rubygems'
22
+ require 'ruby-poker'
23
+
24
+ hand1 = PokerHand.new("8H 9C TC JD QH")
25
+ hand2 = PokerHand.new(["3D", "3C", "3S", "KD", "AH"])
26
+ puts hand1 => 8h 9c Tc Jd Qh (Straight)
27
+ puts hand1.just_cards => 8h 9c Tc Jd Qh
28
+ puts hand1.rank => Straight
29
+ puts hand2 => 3d 3c 3s Kd Ah (Three of a kind)
30
+ puts hand2.rank => Three of a kind
31
+ puts hand1 > hand2 => true
32
+
33
+ == Duplicates
34
+
35
+ By default ruby-poker will not raise an exception if you add the same card to a hand twice. You can tell ruby-poker to not allow duplicates by doing the following
36
+
37
+ PokerHand.allow_duplicates = false
38
+
39
+ Place that line near the beginning of your program. The change is program wide so once allow_duplicates is set to false, _all_ poker hands will raise an exception if a duplicate card is added to the hand.
40
+
41
+ == Compatibility
42
+
43
+ Ruby-Poker is compatible with Ruby 1.8 and Ruby 1.9.
44
+
45
+ == History
46
+
47
+ In the 0.2.0 release Patrick Hurley's Texas Holdem code from http://rubyquiz.com/quiz24.html was merged into ruby-poker.
48
+
49
+ == License
50
+
51
+ This is free software; you can redistribute it and/or modify it under the terms of the BSD license. See LICENSE for more details.
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- Gem::manage_gems
4
3
  require 'rake/rdoctask'
5
4
  require "rake/testtask"
6
5
  require 'rake/gempackagetask'
@@ -11,32 +10,39 @@ rescue LoadError
11
10
  nil
12
11
  end
13
12
 
14
- RUBYPOKER_VERSION = "0.3.0"
13
+ RUBYPOKER_VERSION = "0.3.1"
15
14
 
16
- task :default => [:test]
17
-
18
- spec = Gem::Specification::new do |s|
19
- s.name = "ruby-poker"
20
- s.summary = "Ruby library for comparing poker hands and determining the winner."
21
- s.version = RUBYPOKER_VERSION
22
-
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = "ruby-poker"
17
+ s.version = RUBYPOKER_VERSION
18
+ s.date = "2009-01-24"
23
19
  s.rubyforge_project = "rubypoker"
24
20
  s.platform = Gem::Platform::RUBY
21
+ s.summary = "Poker library in Ruby"
22
+ s.description = "Ruby library for comparing poker hands and determining the winner."
23
+ s.author = "Rob Olson"
24
+ s.email = "rko618@gmail.com"
25
+ s.homepage = "http://github.com/robolson/ruby-poker"
26
+ s.has_rdoc = true
27
+ s.files = ["CHANGELOG",
28
+ "examples/deck.rb",
29
+ "examples/quick_example.rb",
30
+ "lib/card.rb",
31
+ "lib/ruby-poker.rb",
32
+ "LICENSE",
33
+ "Rakefile",
34
+ "README.rdoc",
35
+ "ruby-poker.gemspec"]
36
+ s.test_files = ["test/test_card.rb",
37
+ "test/test_poker_hand.rb"]
38
+ s.require_paths << 'lib'
25
39
 
26
- s.files = Dir.glob("{examples,lib,test}/**/**/*") + ["Rakefile"]
27
- s.require_path = "lib"
28
-
29
- s.has_rdoc = true
30
- s.extra_rdoc_files = ["README", "CHANGELOG", "LICENSE"]
40
+ s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "LICENSE"]
31
41
  s.rdoc_options << '--title' << 'Ruby Poker Documentation' <<
32
- '--main' << 'README' <<
42
+ '--main' << 'README.rdoc' <<
33
43
  '--inline-source' << '-q'
34
44
 
35
- s.test_files = Dir.glob("test/*.rb")
36
-
37
- s.author = "Robert Olson"
38
- s.email = "rko618@gmail.com"
39
- s.homepage = "http://rubyforge.org/projects/rubypoker/"
45
+ # s.add_dependency("thoughtbot-shoulda", ["> 2.0.0"])
40
46
  end
41
47
 
42
48
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -48,6 +54,7 @@ Rake::TestTask.new do |test|
48
54
  test.libs << "test"
49
55
  test.test_files = Dir[ "test/test_*.rb" ]
50
56
  test.verbose = true
57
+ test.warning = true
51
58
  end
52
59
 
53
60
  desc "Start autotest"
@@ -55,9 +62,9 @@ task :autotest do
55
62
  ruby "-I lib -w /usr/bin/autotest"
56
63
  end
57
64
 
58
- Rake::RDocTask.new(:rdoc) do |rdoc|
59
- rdoc.rdoc_files.include('README', 'CHANGELOG', 'LICENSE', 'lib/')
60
- rdoc.main = 'README'
65
+ Rake::RDocTask.new(:docs) do |rdoc|
66
+ rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG', 'LICENSE', 'lib/')
67
+ rdoc.main = 'README.rdoc'
61
68
  rdoc.rdoc_dir = 'doc/html'
62
69
  rdoc.title = 'Ruby Poker Documentation'
63
70
  rdoc.options << '--inline-source'
data/lib/card.rb CHANGED
@@ -115,4 +115,11 @@ class Card
115
115
  def == card2
116
116
  @value == card2.value
117
117
  end
118
+ alias :eql? :==
119
+
120
+ # Compute a hash-code for this Card. Two Cards with the same
121
+ # content will have the same hash code (and will compare using eql?).
122
+ def hash
123
+ @value.hash
124
+ end
118
125
  end
data/lib/ruby-poker.rb CHANGED
@@ -27,6 +27,8 @@ class PokerHand
27
27
  else
28
28
  @hand = cards
29
29
  end
30
+
31
+ check_for_duplicates if !@@allow_duplicates
30
32
  end
31
33
 
32
34
  # Returns a new PokerHand object with the cards sorted by suit
@@ -262,7 +264,7 @@ class PokerHand
262
264
  end
263
265
 
264
266
  # Returns a string of the hand arranged based on its rank. Usually this will be the
265
- # same as `by_face` but there are some cases where it makes a difference.
267
+ # same as by_face but there are some cases where it makes a difference.
266
268
  #
267
269
  # ph = PokerHand.new("AS 3S 5S 2S 4S")
268
270
  # ph.sort_using_rank # => "5s 4s 3s 2s As"
@@ -287,7 +289,7 @@ class PokerHand
287
289
  alias :to_ary :to_a
288
290
 
289
291
  def <=> other_hand
290
- self.score[0] <=> other_hand.score[0]
292
+ self.score[0].compact <=> other_hand.score[0].compact
291
293
  end
292
294
 
293
295
  # Add a card to the hand
@@ -318,7 +320,13 @@ class PokerHand
318
320
  @hand.delete(Card.new(card))
319
321
  end
320
322
 
321
- RESOLVING_METHODS = ['size', '+', '-']
323
+ # Same concept as Array#uniq
324
+ def uniq
325
+ PokerHand.new(@hand.uniq)
326
+ end
327
+
328
+ # Resolving methods are just passed directly down to the @hand array
329
+ RESOLVING_METHODS = [:size, :+, :-]
322
330
  RESOLVING_METHODS.each do |method|
323
331
  class_eval %{
324
332
  def #{method}(*args, &block)
@@ -327,7 +335,13 @@ class PokerHand
327
335
  }
328
336
  end
329
337
 
330
- # protected
338
+ protected
339
+
340
+ def check_for_duplicates
341
+ if @hand.size != @hand.uniq.size && !@@allow_duplicates
342
+ raise "You are attempting to create a hand that contains duplicate cards. Set PokerHand.allow_duplicates to true if you do not want to ignore this error."
343
+ end
344
+ end
331
345
 
332
346
  # if md is a string, arrange_hand will remove extra white space
333
347
  # if md is a MatchData, arrange_hand returns the matched segment
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ruby-poker"
3
+ s.version = "0.3.1"
4
+ s.date = "2009-01-24"
5
+ s.rubyforge_project = "rubypoker"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.summary = "Poker library in Ruby"
8
+ s.description = "Ruby library for comparing poker hands and determining the winner."
9
+ s.author = "Rob Olson"
10
+ s.email = "rko618@gmail.com"
11
+ s.homepage = "http://github.com/robolson/ruby-poker"
12
+ s.has_rdoc = true
13
+ s.files = ["CHANGELOG",
14
+ "examples/deck.rb",
15
+ "examples/quick_example.rb",
16
+ "lib/card.rb",
17
+ "lib/ruby-poker.rb",
18
+ "LICENSE",
19
+ "Rakefile",
20
+ "README.rdoc",
21
+ "ruby-poker.gemspec"]
22
+ s.test_files = ["test/test_card.rb",
23
+ "test/test_poker_hand.rb"]
24
+ s.require_paths << 'lib'
25
+
26
+ s.extra_rdoc_files = ["README", "CHANGELOG", "LICENSE"]
27
+ s.rdoc_options << '--title' << 'Ruby Poker Documentation' <<
28
+ '--main' << 'README.rdoc' <<
29
+ '--inline-source' << '-q'
30
+
31
+ # s.add_dependency("thoughtbot-shoulda", ["> 2.0.0"])
32
+ end
data/test/test_card.rb CHANGED
@@ -52,4 +52,8 @@ class TestCard < Test::Unit::TestCase
52
52
  assert_not_equal(@c1, c)
53
53
  assert_equal(@c1, @c1)
54
54
  end
55
+
56
+ def test_hash
57
+ assert_equal(15, @c1.hash)
58
+ end
55
59
  end
@@ -1,165 +1,210 @@
1
- require 'test/unit'
2
1
  require 'ruby-poker.rb'
2
+ require 'rubygems'
3
+ require 'shoulda'
3
4
 
4
5
  class TestPokerHand < Test::Unit::TestCase
5
- def setup
6
- @trips = PokerHand.new("2D 9C AS AH AC")
7
- @full_boat = PokerHand.new(["2H", "2D", "4C", "4D", "4S"])
8
- @flush = PokerHand.new("3D 6D 7D TD QD 5H 2S")
9
- @straight = PokerHand.new("8H 9D TS JH QC AS")
10
- end
6
+ context "A PokerHand instance" do
7
+
8
+ setup do
9
+ @trips = PokerHand.new("2D 9C AS AH AC")
10
+ @full_boat = PokerHand.new(["2H", "2D", "4C", "4D", "4S"])
11
+ @flush = PokerHand.new("3D 6D 7D TD QD 5H 2S")
12
+ @straight = PokerHand.new("8H 9D TS JH QC AS")
13
+ end
11
14
 
12
- # there are a lot of combinations that should be tested here. I will add more
13
- # troublesome cases as I think of them.
14
- def test_sort_using_rank
15
- assert_equal("As Ah Ac 9c 2d", @trips.sort_using_rank)
16
- assert_equal("4s 4d 4c 2h 2d", @full_boat.sort_using_rank)
17
- assert_equal("Qd Td 7d 6d 3d 2s 5h", @flush.sort_using_rank)
18
- assert_equal("Qc Jh Ts 9d 8h As", @straight.sort_using_rank)
15
+ # there are a lot of combinations that should be tested here. I will add more
16
+ # troublesome cases as I think of them.
17
+ should "sort using rank" do
18
+ assert_equal("As Ah Ac 9c 2d", @trips.sort_using_rank)
19
+ assert_equal("4s 4d 4c 2h 2d", @full_boat.sort_using_rank)
20
+ assert_equal("Qd Td 7d 6d 3d 2s 5h", @flush.sort_using_rank)
21
+ assert_equal("Qc Jh Ts 9d 8h As", @straight.sort_using_rank)
19
22
 
20
- assert_equal("As Ah 3d 3c Kd", PokerHand.new("AS AH KD 3D 3C").sort_using_rank)
21
- assert_equal("As Ah 3d 3c 2d", PokerHand.new("2D AS AH 3D 3C").sort_using_rank)
22
- end
23
-
24
- def test_by_face
25
- assert_equal([13, 13, 13, 8, 1], @trips.by_face.hand.collect {|c| c.face})
26
- end
27
-
28
- def test_by_suit
29
- assert_equal([3, 2, 1, 0, 0], @trips.by_suit.hand.collect {|c| c.suit})
30
- end
31
-
32
- def test_face_values
33
- assert_equal([1, 8, 13, 13, 13], @trips.face_values)
34
- end
23
+ assert_equal("As Ah 3d 3c Kd", PokerHand.new("AS AH KD 3D 3C").sort_using_rank)
24
+ assert_equal("As Ah 3d 3c 2d", PokerHand.new("2D AS AH 3D 3C").sort_using_rank)
25
+ end
35
26
 
36
- def test_flush
37
- assert @flush.flush?
38
- assert !@trips.flush?
39
- end
27
+ should "return card sorted by face value" do
28
+ assert_equal([13, 13, 13, 8, 1], @trips.by_face.hand.collect {|c| c.face})
29
+ end
40
30
 
41
- def test_four_of_a_kind
42
- assert !@trips.four_of_a_kind?
43
- assert PokerHand.new("AD 9C AS AH AC")
44
- end
31
+ should "return cards sorted by suit" do
32
+ assert_equal([3, 2, 1, 0, 0], @trips.by_suit.hand.collect {|c| c.suit})
33
+ end
45
34
 
46
- def test_full_house
47
- assert !@trips.full_house?
48
- assert @full_boat.full_house?
49
- end
35
+ should "return just the face values of the cards" do
36
+ assert_equal([1, 8, 13, 13, 13], @trips.face_values)
37
+ end
38
+
39
+ should "recognize a straight flush" do
40
+ assert !@flush.straight_flush?
41
+ assert !@straight.straight_flush?
42
+ assert PokerHand.new("8H 9H TH JH QH AS").straight_flush?
43
+ end
44
+
45
+ should "recognize a royal flush" do
46
+ assert !@flush.royal_flush?
47
+ assert PokerHand.new("AD KD QD JD TD").royal_flush?
48
+ end
50
49
 
51
- def test_hand
52
- assert_equal 5, @trips.hand.size
53
- assert_instance_of Card, @trips.hand[0]
54
- end
50
+ should "recognize a flush" do
51
+ assert @flush.flush?
52
+ assert !@trips.flush?
53
+ end
55
54
 
56
- def test_hand_rating
57
- assert_equal "Three of a kind", @trips.hand_rating
58
- assert_equal "Full house", @full_boat.hand_rating
59
- end
55
+ should "recognize a four of a kind" do
56
+ assert !@trips.four_of_a_kind?
57
+ assert PokerHand.new("AD 9C AS AH AC")
58
+ end
60
59
 
61
- def test_rank
62
- # rank is an alias for hand_rating
63
- assert_not_nil @trips.rank
64
- end
60
+ should "recognize a full house" do
61
+ assert !@trips.full_house?
62
+ assert @full_boat.full_house?
63
+ end
64
+
65
+ should "recognize a straight" do
66
+ assert @straight.straight?
67
+ assert PokerHand.new("AH 2S 3D 4H 5D").straight?
68
+ end
65
69
 
66
- def test_highest_card
67
- # hard to test, make sure it does not return null
68
- assert PokerHand.new("2D 4S 6C 8C TH").highest_card?
69
- end
70
+ should "recognize a three of a kind" do
71
+ assert @trips.three_of_a_kind?
72
+ end
70
73
 
71
- def test_just_cards
72
- assert_equal("2d 9c As Ah Ac", @trips.just_cards)
73
- end
74
+ should "recognize a two pair" do
75
+ assert PokerHand.new("2S 2D TH TD 4S").two_pair?
76
+ assert !PokerHand.new("6D 7C 5D 5H 3S").two_pair?
77
+ end
78
+
79
+ should "recognize a pair" do
80
+ assert !PokerHand.new("5C JC 2H 7S 3D").pair?
81
+ assert PokerHand.new("6D 7C 5D 5H 3S").pair?
82
+ end
83
+
84
+ should "recognize a hand with the rank highest_card" do
85
+ # hard to test, make sure it does not return null
86
+ assert PokerHand.new("2D 4S 6C 8C TH").highest_card?
87
+ end
74
88
 
75
- def test_pair
76
- assert !PokerHand.new("5C JC 2H 7S 3D").pair?
77
- assert PokerHand.new("6D 7C 5D 5H 3S").pair?
78
- end
79
-
80
- def test_royal_flush
81
- assert !@flush.royal_flush?
82
- assert PokerHand.new("AD KD QD JD TD").royal_flush?
83
- end
89
+ should "have an instance variable hand that is an array of Cards" do
90
+ assert_instance_of Card, @trips.hand[0]
91
+ end
84
92
 
85
- def test_score
86
- assert_equal([4, 13, 8, 1], @trips.score[0])
87
- end
93
+ should "return the hand's rating as a string" do
94
+ assert_equal "Three of a kind", @trips.hand_rating
95
+ assert_equal "Full house", @full_boat.hand_rating
96
+ end
88
97
 
89
- def test_straight
90
- assert @straight.straight?
91
- assert PokerHand.new("AH 2S 3D 4H 5D").straight?
92
- end
98
+ should "respond to rank" do
99
+ # rank is an alias for hand_rating
100
+ assert_respond_to @trips, :rank
101
+ end
93
102
 
94
- def test_straight_flush
95
- assert !@flush.straight_flush?
96
- assert !@straight.straight_flush?
97
- assert PokerHand.new("8H 9H TH JH QH AS").straight_flush?
98
- end
103
+ should "return the hand as a string" do
104
+ assert_equal("2d 9c As Ah Ac", @trips.just_cards)
105
+ end
99
106
 
100
- def test_three_of_a_kind
101
- assert @trips.three_of_a_kind?
102
- end
107
+ should "return the hand's score" do
108
+ assert_equal([4, 13, 8, 1], @trips.score[0])
109
+ end
103
110
 
104
- def test_two_pair
105
- assert PokerHand.new("2S 2D TH TD 4S").two_pair?
106
- assert !PokerHand.new("6D 7C 5D 5H 3S").two_pair?
107
- end
108
-
109
- def test_matching
110
- assert_match(/9c/, @trips)
111
- end
111
+ should "be able to match regular expressions" do
112
+ assert_match(/9c/, @trips.to_s)
113
+ assert_no_match(/AD/, @trips.to_s)
114
+ end
112
115
 
113
- def test_size
114
- assert_equal(2, PokerHand.new("2c 3d").size)
115
- end
116
+ should "return the correct number of cards in the hand" do
117
+ assert_equal(2, PokerHand.new("2c 3d").size)
118
+ end
116
119
 
117
- def test_comparisons
118
- hand1 = PokerHand.new("5C JC 2H 5S 3D")
119
- hand2 = PokerHand.new("6D 7C 5D 5H 3S")
120
- assert_equal(1, hand1 <=> hand2)
121
- assert_equal(-1, hand2 <=> hand1)
122
- end
120
+ should "be comparable to other PokerHands" do
121
+ hand1 = PokerHand.new("5C JC 2H 5S 3D")
122
+ hand2 = PokerHand.new("6D 7C 5D 5H 3S")
123
+ assert_equal(1, hand1 <=> hand2)
124
+ assert_equal(-1, hand2 <=> hand1)
125
+ end
123
126
 
124
- def test_equality
125
- assert_equal(0, @trips <=> @trips)
127
+ should "be considered equal to other poker hands that contain the same cards" do
128
+ assert_equal(0, @trips <=> @trips)
126
129
 
127
- hand1 = PokerHand.new("Ac Qc Ks Kd 9d 3c")
128
- hand2 = PokerHand.new("Ah Qs 9h Kh Kc 3s")
129
- assert_equal(0, hand1 <=> hand2)
130
- end
130
+ hand1 = PokerHand.new("Ac Qc Ks Kd 9d 3c")
131
+ hand2 = PokerHand.new("Ah Qs 9h Kh Kc 3s")
132
+ assert_equal(0, hand1 <=> hand2)
133
+ end
131
134
 
132
- def test_appending
133
- ph = PokerHand.new()
134
- ph << "Qd"
135
- ph << Card.new("2D")
136
- ph << ["3d", "4d"]
137
- assert_equal("Qd 2d 3d 4d", ph.just_cards)
138
- end
135
+ should "be able to add a Card to itself" do
136
+ ph = PokerHand.new()
137
+ ph << "Qd"
138
+ ph << Card.new("2D")
139
+ ph << ["3d", "4d"]
140
+ assert_equal("Qd 2d 3d 4d", ph.just_cards)
141
+ end
139
142
 
140
- def test_delete
141
- ph = PokerHand.new("Ac")
142
- ph.delete("Ac")
143
- assert_equal(Array.new, ph.hand)
144
- end
143
+ should "be able to delete a card" do
144
+ ph = PokerHand.new("Ac")
145
+ ph.delete("Ac")
146
+ assert_equal(Array.new, ph.hand)
147
+ end
145
148
 
146
- def test_five_of_a_kind
147
- # there is no five of a kind. This just tests to make sure
148
- # that ruby-poker doesn't crash if given 5 of the same card
149
- ph = PokerHand.new("KS KS KS KS KS")
150
- assert_equal("Four of a kind", ph.rank)
151
- end
149
+ context "when duplicates are allowed" do
150
+ setup do
151
+ PokerHand.allow_duplicates = true
152
+ end
153
+
154
+ should "create a PokerHand of unique cards" do
155
+ uniq_ph = PokerHand.new("3s 4s 3s").uniq
156
+ assert_instance_of(PokerHand, uniq_ph) # want to be sure uniq hands back a PokerHand
157
+ assert_contains(uniq_ph.hand, Card.new('3s'))
158
+ assert_contains(uniq_ph.hand, Card.new('4s'))
159
+ end
160
+
161
+ should "allow five of a kind" do
162
+ # there is no five of a kind. This just tests to make sure
163
+ # that ruby-poker doesn't crash if given 5 of the same card
164
+ ph = PokerHand.new("KS KS KS KS KS")
165
+ assert_equal("Four of a kind", ph.rank)
166
+ end
152
167
 
153
- def test_duplicates
154
- ph = PokerHand.new("2d")
155
- PokerHand.allow_duplicates = true
156
- ph << "2d"
157
- assert_equal("2d 2d", ph.just_cards)
168
+ should "allow duplicates on initialize" do
169
+ assert_nothing_raised RuntimeError do
170
+ PokerHand.new("3s 3s")
171
+ end
172
+ end
158
173
 
159
- PokerHand.allow_duplicates = false
160
- assert_raise RuntimeError do
161
- ph << "2d"
174
+ should "allow duplicate card to be added after initialize" do
175
+ ph = PokerHand.new("2d")
176
+ ph << "2d"
177
+ assert_equal("2d 2d", ph.just_cards)
178
+ end
162
179
  end
180
+
181
+ context "when duplicates are not allowed" do
182
+ setup do
183
+ PokerHand.allow_duplicates = false
184
+ end
185
+
186
+ should "not allow duplicates on initialize" do
187
+ PokerHand.allow_duplicates = false
188
+
189
+ assert_raise RuntimeError do
190
+ PokerHand.new("3s 3s")
191
+ end
192
+
193
+ PokerHand.allow_duplicates = true
194
+ end
195
+
196
+ should "not allow duplicates after initialize" do
197
+ PokerHand.allow_duplicates = false
198
+
199
+ ph = PokerHand.new("2d")
200
+ assert_raise RuntimeError do
201
+ ph << "2d"
202
+ end
203
+
204
+ PokerHand.allow_duplicates = true
205
+ end
206
+ end
207
+
163
208
  end
164
209
  end
165
210
 
metadata CHANGED
@@ -1,51 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-poker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
- - Robert Olson
7
+ - Rob Olson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-26 00:00:00 -07:00
12
+ date: 2009-01-24 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description:
16
+ description: Ruby library for comparing poker hands and determining the winner.
17
17
  email: rko618@gmail.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README
23
+ - README.rdoc
24
24
  - CHANGELOG
25
25
  - LICENSE
26
26
  files:
27
+ - CHANGELOG
27
28
  - examples/deck.rb
28
29
  - examples/quick_example.rb
29
30
  - lib/card.rb
30
31
  - lib/ruby-poker.rb
31
- - test/test_card.rb
32
- - test/test_poker_hand.rb
33
- - Rakefile
34
- - README
35
- - CHANGELOG
36
32
  - LICENSE
33
+ - Rakefile
34
+ - README.rdoc
35
+ - ruby-poker.gemspec
37
36
  has_rdoc: true
38
- homepage: http://rubyforge.org/projects/rubypoker/
37
+ homepage: http://github.com/robolson/ruby-poker
39
38
  post_install_message:
40
39
  rdoc_options:
41
40
  - --title
42
41
  - Ruby Poker Documentation
43
42
  - --main
44
- - README
43
+ - README.rdoc
45
44
  - --inline-source
46
45
  - -q
47
46
  require_paths:
48
47
  - lib
48
+ - lib
49
49
  required_ruby_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
@@ -61,10 +61,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  requirements: []
62
62
 
63
63
  rubyforge_project: rubypoker
64
- rubygems_version: 1.1.1
64
+ rubygems_version: 1.3.1
65
65
  signing_key:
66
66
  specification_version: 2
67
- summary: Ruby library for comparing poker hands and determining the winner.
67
+ summary: Poker library in Ruby
68
68
  test_files:
69
69
  - test/test_card.rb
70
70
  - test/test_poker_hand.rb
data/README DELETED
@@ -1,63 +0,0 @@
1
- = Poker hand evaluator for Ruby
2
-
3
- == Author
4
-
5
- Robert Olson (rko618 [at] gmail [dot] com)
6
-
7
- == License
8
-
9
- This is free software; you can redistribute it and/or modify it under the
10
- terms of the BSD license. See LICENSE for more details.
11
-
12
- == Download
13
-
14
- The latest version of <b>ruby poker</b> can be found at
15
-
16
- http://rubyforge.org/frs/?group_id=5257
17
-
18
- The homepage of this project is located at
19
-
20
- http://rubyforge.org/projects/rubypoker
21
-
22
- == Description
23
-
24
- Ruby-Poker handles the logic for getting the rank of a poker hand. It can also be used
25
- to compare two or more hands to determine which hand has the highest poker value.
26
-
27
- Card representations can be passed to the PokerHand constructor as a string or an array.
28
- Face cards (cards ten, jack, queen, king, and ace) are created using their
29
- letter representation (T, J, Q, K, A).
30
-
31
- == Examples
32
-
33
- In this section some examples show what can be done with this class.
34
-
35
- hand1 = PokerHand.new("8H 9C TC JD QH")
36
- hand2 = PokerHand.new(["3D", "3C", "3S", "KD", "AH"])
37
- puts hand1 => 8h 9c Tc Jd Qh (Straight)
38
- puts hand1.just_cards => 8h 9c Tc Jd Qh
39
- puts hand1.rank => Straight
40
- puts hand2 => 3d 3c 3s Kd Ah (Three of a kind)
41
- puts hand2.rank => Three of a kind
42
- puts hand1 > hand2 => true
43
-
44
- == Duplicates
45
-
46
- By default ruby-poker will not raise an exception if you add the same card to a hand
47
- twice. You can tell ruby-poker to not allow duplicates by doing the following
48
-
49
- PokerHand.allow_duplicates = false
50
-
51
- Place that line near the beginning of your program. The change is program wide so
52
- once allow_duplicates is set to false, _all_ poker hands will raise an exception
53
- if a duplicate card is added to the hand.
54
-
55
- == Compatibility
56
-
57
- Ruby-Poker is compatible with Ruby 1.8 and Ruby 1.9.
58
-
59
- == Background
60
-
61
- The original version of ruby-poker was written entirely by myself (Robert Olson).
62
- As of the 0.2.0 release ruby-poker incorporates Patrick Hurley's Texas
63
- Holdem code from http://rubyquiz.com/quiz24.html which I merged into ruby-poker.