Last active
August 29, 2015 14:02
-
-
Save Murphydbuffalo/24615508dc6eba65642c to your computer and use it in GitHub Desktop.
Solution to quick Cards challenge (object-oriented design reading_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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