Created
October 14, 2015 22:20
-
-
Save arightious/ddc600fc59cb26ec5f83 to your computer and use it in GitHub Desktop.
Firehose Card Challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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