public
Description: Ruby library for comparing poker hands and determining the winner.
Homepage:
Clone URL: git://github.com/robolson/ruby-poker.git
Jonathan Wilkins (author)
Tue Oct 27 01:25:13 -0700 2009
robolson (committer)
Mon Nov 09 23:04:52 -0800 2009
commit  d62b6191e95a527c3d10f7d04183727a0d435962
tree    b204e39f8f5da60649407ea0839b697617c67a50
parent  656203400f3897b310c9d00a4125bd1df95de0bf
name age message
file .gitignore Mon Jul 27 21:41:52 -0700 2009 version bump to 0.3.2 [robolson]
file CHANGELOG Sun Jul 12 01:20:02 -0700 2009 Reorganized ruby-poker's lib folder to match th... [robolson]
file LICENSE Thu Jan 10 03:20:07 -0800 2008 Version 0.0.1: Poker hand evaluations for a 5 c... [robolson]
file README.rdoc Mon Jul 27 21:41:52 -0700 2009 version bump to 0.3.2 [robolson]
file Rakefile Mon Jul 27 21:41:52 -0700 2009 version bump to 0.3.2 [robolson]
directory examples/ Sun Jun 21 01:38:43 -0700 2009 Rescind my decision to add a ! to the end of th... [robolson]
directory lib/ Loading commit data...
file ruby-poker.gemspec Mon Jul 27 22:04:45 -0700 2009 0.3.2 release hiccup. Gemspec fixed [robolson]
directory test/
README.rdoc

Poker library in Ruby

Author:Rob Olson
Email:[first name] [at] thinkingdigitally.com
GitHub:github.com/robolson/ruby-poker

Description

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.

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).

Install

    sudo gem install ruby-poker

Example

    require 'rubygems'
    require 'ruby-poker'

    hand1 = PokerHand.new("8H 9C TC JD QH")
    hand2 = PokerHand.new(["3D", "3C", "3S", "KD", "AH"])
    puts hand1                => 8h 9c Tc Jd Qh (Straight)
    puts hand1.just_cards     => 8h 9c Tc Jd Qh
    puts hand1.rank           => Straight
    puts hand2                => 3d 3c 3s Kd Ah (Three of a kind)
    puts hand2.rank           => Three of a kind
    puts hand1 > hand2        => true

Duplicates

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

    PokerHand.allow_duplicates = false

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.

Compatibility

Ruby-Poker is compatible with Ruby 1.8.6 and Ruby 1.9.1.

History

In the 0.2.0 release Patrick Hurley’s Texas Holdem code from www.rubyquiz.com/quiz24.html was merged into ruby-poker.

License

This is free software; you can redistribute it and/or modify it under the terms of the BSD license. See LICENSE for more details.