Skip to content

Instantly share code, notes, and snippets.

@OrangeCrush
Created July 20, 2013 19:12
Show Gist options
  • Save OrangeCrush/6046115 to your computer and use it in GitHub Desktop.
Save OrangeCrush/6046115 to your computer and use it in GitHub Desktop.
Quick deck of cards in JSON.
#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)
@OrangeCrush
Copy link
Author

Note that this is just for A-K

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment