Created
August 29, 2014 15:34
-
-
Save foglabs/ac965a3935f3c5b8a290 to your computer and use it in GitHub Desktop.
OOP Card Example
This file contains 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 | |
def initialize(rank = nil, suit = nil) | |
if suit.nil? | |
@suit = ['♠', '♣', '♥', '♦'].sample | |
else | |
@suit = suit | |
end | |
if rank.nil? | |
@rank = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'].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