Skip to content

Instantly share code, notes, and snippets.

@Murphydbuffalo
Last active Aug 29, 2015
Embed
What would you like to do?
Solution to quick Cards challenge (object-oriented design reading_
class Card
attr_reader :rank, :suit
def initialize(rank=nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
if rank.nil?
face_cards = ["J", "Q", "K", "A"]
all_cards = (1..10).to_a
face_cards.each {|card| all_cards << card}
@rank = all_cards.sample
else
@rank = rank
end
puts "Create a new card: #{@rank} of #{@suit}"
end
end
5.times { Card.new }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment