Skip to content

Instantly share code, notes, and snippets.

@humeji
Created June 17, 2019 02:41
Show Gist options
  • Save humeji/6052bfebca3ca6b64cd5f6d2fe437cf9 to your computer and use it in GitHub Desktop.
Save humeji/6052bfebca3ca6b64cd5f6d2fe437cf9 to your computer and use it in GitHub Desktop.
# This Class would create an instance of a Card object
class Card
attr_accessor :rank, :suit
def initialize(rank, suit)
@rank = rank
@suit = suit
end
def output_card
"#{rank} of #{suit}"
end
def self.random_card
suit = ['hearts', 'spades', 'clubs', 'diamonds']
Card.new(rand(1..13), suit.sample)
end
end
# this would create multiple sets of cards
class Deck
def initialize
d = 0
@cards = []
while d < 13
@cards << Card.random_card
d += 1
end
end
def shuffle
@cards.shuffle!
end
def output
@cards.each do |card|
puts card
end
end
def deal
shuffle
dealing = @cards.shift
puts dealing.output_card
end
end
deck = Deck.new
#Should deal a random card from the deck.
deck.deal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment