Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Card
- attr_accessor :rank, :suite
- def initialize(rank, suite)
- @rank = rank
- @suite = suite
- end
- def output_card
- puts "#{self.rank} of #{self.suite}"
- end
- def self.random_card
- Card.new(rand(10), :spades)
- end
- end
- class Deck
- def initialize
- @cards = []
- ranks = ['Ace', 2 , 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']
- suites = ['Diamond', 'Clubs', 'Spades', 'Hearts']
- suites.each do |suit|
- ranks.each do |rank|
- @cards << "#{rank} of #{suit}"
- end
- end
- end
- def shuffle
- @cards.shuffle!
- end
- def deal
- @cards.shift
- end
- end
- p deck = Deck.new
- deck.shuffle
- p deck.deal
Add Comment
Please, Sign In to add comment