Skip to content

Instantly share code, notes, and snippets.

@mrjabba
Created December 4, 2010 03:37
Show Gist options
  • Save mrjabba/727893 to your computer and use it in GitHub Desktop.
Save mrjabba/727893 to your computer and use it in GitHub Desktop.
creating a deck of cards and shuffling in 4 lines of Ruby code -> via Dec Ruby issue PragPub -> http://www.pragprog.com/news/pragmatic-programmer-magazine-special-ruby-issue
suits = %w{ C D H S }
ranks = [ *'2'..'10', *%w{ J Q K A } ]
deck = suits
.product(ranks)
.map(&:join)
hands = deck
.shuffle
.each_slice(13)
puts hands.first.join(", ")
@YevKo
Copy link

YevKo commented Dec 2, 2014

Line 2: syntax error, unexpected ',', expecting ']'
ranks = [ *'2'..'10', *%w{ J Q K A } ]
^
Line 2: syntax error, unexpected ']', expecting tCOLON2 or '[' or '.'
ranks = [ *'2'..'10', *%w{ J Q K A } ]
^
Line 4: syntax error, unexpected '.', expecting $end
.product(ranks)
^

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