Skip to content

Instantly share code, notes, and snippets.

@glassbead0
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glassbead0/a6abce6794bb913429b1 to your computer and use it in GitHub Desktop.
Save glassbead0/a6abce6794bb913429b1 to your computer and use it in GitHub Desktop.
class Card
attr_reader :suit
attr_reader :value
def initialize(value, suit)
get_suit(suit)
get_value(value)
end
def get_suit(suit) # gets the suit, but rejects invalid suits
if [:♠, :♦, :♣, :♥].include?(suit)
@suit = suit
else
fail(ArgumentError, 'not a valid suit')
end
end
def get_value(value) # gets the value, but rejects invalid values.
@value = value
@value = :A if value == 1
@value = :J if value == 11
@value = :Q if value == 12
@value = :K if value == 13
if value < 1 || value > 13
fail(ArgumentError, 'not a valid value for a card')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment