Skip to content

Instantly share code, notes, and snippets.

@pshushereba
Created January 22, 2016 02:48
Show Gist options
  • Save pshushereba/090d4e7e46812e8cc962 to your computer and use it in GitHub Desktop.
Save pshushereba/090d4e7e46812e8cc962 to your computer and use it in GitHub Desktop.
Completed deck.rb program for the Firehose Project
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
end
class Deck
def initialize
@deck = []
@rank = ['A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K']
@suit = [:spades, :diamonds, :clubs, :hearts]
@rank.each do |rank|
@suit.each do |suit|
@deck.push(Card.new(rank, suit))
end
end
#puts @deck
#puts @deck.first.rank
end
def shuffle
@deck.shuffle!
@deck.each { |card| card.output_card }
end
def deal
puts @deck.shift.output_card
end
end
deck1 = Deck.new
deck1.shuffle
puts '------------'
puts deck1.deal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment