Created
July 20, 2013 19:12
-
-
Save OrangeCrush/6046115 to your computer and use it in GitHub Desktop.
Quick deck of cards in JSON.
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
#Build a deck of cards in json | |
require 'json' | |
class Card | |
attr_reader :value, :suit | |
def initialize(val,suit) | |
@value = val | |
@suit = suit | |
end | |
def to_json | |
{'value' => @value, 'suit' => @suit} | |
end | |
end | |
deck = [] | |
cards = ['A', '9', '10', 'J', 'Q', 'K'] | |
suit = ['S', 'C', 'H', 'D'] | |
cards.product(suit).each do |value, suit2| | |
deck << Card.new(value,suit2).to_json | |
end | |
puts JSON.pretty_generate(deck) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this is just for A-K