Skip to content

Instantly share code, notes, and snippets.

@arightious
Created October 14, 2015 22:20
Show Gist options
  • Save arightious/ddc600fc59cb26ec5f83 to your computer and use it in GitHub Desktop.
Save arightious/ddc600fc59cb26ec5f83 to your computer and use it in GitHub Desktop.
Firehose Card Challenge
class Card
attr_accessor :rank, :suit
def initialize(rank, suit)
self.rank = rank
self.suit = suit
end
def output_card
puts "#{self.rank} of #{self.suit}"
end
end
class Deck
def initialize
@cards = []
ranks = %w{2 3 4 5 6 7 8 9 10 Jack Queen King Ace}
suits = %w{spades clubs hearts diamonds}
ranks.each do |rank|
suits.each do |suit|
@cards << Card.new(rank, suit)
end
end
end
def shuffle
#why not use .sample?
@cards.shuffle!
end
def deal
@cards.shift
end
end
deck = Deck.new
deck.shuffle
deck.deal.output_card
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment