-
-
Save lzychowski/055b82ef901c77d14a718ee1b9d9ee55 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) | |
self.rank = rank | |
self.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 | |
possible_cards = [2,3,4,5,6,7,8,9,10, "K", "Q", "J", "A"] | |
@cards = [] | |
possible_cards.each do |card| | |
@cards << Card.new(card, :spades) | |
@cards << Card.new(card, :clubs) | |
@cards << Card.new(card, :diamonds) | |
@cards << Card.new(card, :hearts) | |
end | |
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.shuffle | |
deck.deal.output_card |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment