Skip to content

Instantly share code, notes, and snippets.

@Murphydbuffalo
Last active August 29, 2015 14:02
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 Murphydbuffalo/24615508dc6eba65642c to your computer and use it in GitHub Desktop.
Save Murphydbuffalo/24615508dc6eba65642c to your computer and use it in GitHub Desktop.
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