Skip to content

Instantly share code, notes, and snippets.

View coxandrew's full-sized avatar

Andrew Cox coxandrew

View GitHub Profile
module PlayingCards
class Card
class InvalidCardError < ArgumentError
end
include Comparable
SUITS = %w{ spades clubs hearts diamonds }
RANKS = %w{ 2 3 4 5 6 7 8 9 10 J Q K A }
# Original module with "magic numbers" for 4 suits and 13 card values
# See: http://refactoring.com/catalog/replaceMagicNumberWithSymbolicConstant.html
module PlayingCards
SUITS = %w{ spades clubs hearts diamonds }
class Deck
attr_accessor :cards
def initialize
class Object
def self.gimme_attrs(attr)
define_method("#{attr}") do
instance_variable_get "@#{attr}"
end
define_method("#{attr}=") do |attribute|
instance_variable_set :"@#{attr}", attribute
end
end