Skip to content

Instantly share code, notes, and snippets.

@amacdougall
Created December 21, 2015 22:27
Show Gist options
  • Save amacdougall/e33ffa3350f6bc011439 to your computer and use it in GitHub Desktop.
Save amacdougall/e33ffa3350f6bc011439 to your computer and use it in GitHub Desktop.
Deal With It
# Customize FACE_CARDS, JOKERS, and SUITS however you like. Run this file by
# simply typing this at the command line:
#
# ruby deal.rb number_of_cards
#
# If number_of_cards is omitted, you'll get five. And obviously Ruby has to be
# installed, you have to be in the directory that contains the file (or supply
# the path to it), etc.
class Deck
FACE_CARDS = {
11 => "Jack",
12 => "Queen",
13 => "King"
}
JOKERS = [
"Jack Nicholson",
"Mark Hammill",
"Heath Ledger",
"Cesar Romero",
"Jared Leto for some goddamn reason"
]
SUITS = [
"Clubs",
"Diamonds",
"Hearts",
"Spades",
"Wings",
"Flowers",
"Claws",
"Thorns"
]
attr_accessor :cards
def initialize()
self.cards = SUITS.map {|name| suit(name)}.flatten
self.cards += [
]
self.cards.shuffle!
end
def suit(name)
(1..13).map {|n| card(name, n)}
end
def card(suit_name, value)
card_name = value > 10 ? FACE_CARDS[value] : value.to_s
{
suit: suit_name,
value: value,
title: "#{card_name} of #{suit_name}"
}
end
def joker(name)
{
suit: "Joker",
value: -1,
title: name
}
end
def deal(n)
self.cards.pop(n)
end
end
cards_requested = ARGV[0].to_i || 5
deck = Deck.new
puts deck.deal(cards_requested).map {|card| card[:title]}.join("\r\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment