Created
January 15, 2016 05:39
-
-
Save pshushereba/33efe08bc64c868560f0 to your computer and use it in GitHub Desktop.
Attempt to solve the card deck problem
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 | |
attr_accessor :rank, :suit | |
def initialize(rank, suit) | |
@rank = rank | |
@suit = suit | |
end | |
def output_card | |
puts "#{self.rank} of #{self.suit}" | |
end | |
#def self.random_card | |
#Card.new(rand(10), :spades) | |
#end | |
def suit | |
@suit = ['spades', 'clubs', 'hearts', 'diamonds'] | |
end | |
def rank | |
@rank = ['A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K'] | |
end | |
end | |
class Deck < class Card | |
def initialize | |
@cards = [] | |
@deck = rank.product(suit) do |rank, suit| | |
cards.push(Card.new(rank, suit)) | |
end | |
puts @deck | |
end | |
#@deck = { hearts: (2..10).to_a + ['J', 'Q', 'K', 'A'], | |
#diamonds: (2..10).to_a + ['J', 'Q', 'K', 'A'], | |
#clubs: (2..10).to_a + ['J', 'Q', 'K', 'A'], | |
#spades: (2..10).to_a + ['J', 'Q', 'K', 'A'] } | |
#end | |
def shuffle | |
@deck.shuffle! | |
end | |
def deal | |
puts @deck.shift | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment