Created
April 27, 2016 01:03
-
-
Save milothiesen/ab861d9823cefbff8835540ec649aece to your computer and use it in GitHub Desktop.
This file contains 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) | |
@rank = rank | |
@suit = suit | |
end | |
def output_card | |
puts "#{self.rank} of #{self.suit}" | |
end | |
def self.random_card | |
Card.new(rand(10), :spades) | |
end | |
end | |
class Deck | |
def initialize | |
@cards = [] | |
@ranks = (2..10).to_a + ["Jack", "Queen", "King", "Ace"] | |
@suits = ["Diamonds", "Hearts", "Clubs", "Spades"] | |
end | |
def build_deck | |
@suits.each do |suit| | |
@ranks.each do |rank| | |
@cards << Card.new(rank, suit) | |
end | |
end | |
@cards | |
end | |
def shuffle | |
@cards.shuffle! | |
end | |
def deal | |
@cards.shift | |
end | |
def output | |
@cards.each do |card| | |
card.output_card | |
end | |
end | |
end | |
deck = Deck.new | |
deck.build_deck | |
deck.shuffle | |
deck.deal.output_card |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment