Skip to content

Instantly share code, notes, and snippets.

@lzychowski
Created February 5, 2020 23:30
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 lzychowski/055b82ef901c77d14a718ee1b9d9ee55 to your computer and use it in GitHub Desktop.
Save lzychowski/055b82ef901c77d14a718ee1b9d9ee55 to your computer and use it in GitHub Desktop.
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