daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Nov 21st, 2017 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Card
  2.     attr_accessor :rank, :suite
  3.    
  4.     def initialize(rank, suite)
  5.         @rank = rank
  6.         @suite = suite
  7.     end
  8.  
  9.     def output_card
  10.         puts "#{self.rank} of #{self.suite}"
  11.     end
  12.  
  13.     def self.random_card
  14.         Card.new(rand(10), :spades)
  15.     end
  16.  
  17. end
  18.  
  19. class Deck
  20.     def initialize
  21.         @cards = []
  22.         ranks = ['Ace', 2 , 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']
  23.         suites = ['Diamond', 'Clubs', 'Spades', 'Hearts']
  24.        
  25.         suites.each do |suit|
  26.           ranks.each do |rank|
  27.             @cards <<  "#{rank} of #{suit}"
  28.           end
  29.         end
  30.     end
  31.  
  32.     def shuffle
  33.         @cards.shuffle!
  34.     end
  35.  
  36.     def deal
  37.         @cards.shift
  38.     end
  39. end
  40.  
  41. p deck = Deck.new
  42. deck.shuffle
  43. p deck.deal
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top