Last active
August 29, 2015 13:56
-
-
Save cronin101/9312791 to your computer and use it in GitHub Desktop.
Array#Product
This file contains hidden or 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
| people = %i{Jacob James Maithu} | |
| # => [:Jacob, :James, :Maithu] | |
| bike_colours = %i{Red Black White} | |
| # => [:Red, :Black, :White] | |
| helmet_choices = [true, false] | |
| # => [true, false] | |
| people.product(bike_colours, helmet_choices).map do |p, c, h| | |
| "#{p} riding a #{c} bike, #{h ? 'with' : 'without'} a helmet." | |
| end | |
| # => ["Jacob riding a Red bike, with a helmet.", | |
| # "Jacob riding a Red bike, without a helmet.", | |
| # "Jacob riding a Black bike, with a helmet.", | |
| # "Jacob riding a Black bike, without a helmet.", | |
| # "Jacob riding a White bike, with a helmet.", | |
| # "Jacob riding a White bike, without a helmet.", | |
| # "James riding a Red bike, with a helmet.", | |
| # "James riding a Red bike, without a helmet.", | |
| # "James riding a Black bike, with a helmet.", | |
| # "James riding a Black bike, without a helmet.", | |
| # "James riding a White bike, with a helmet.", | |
| # "James riding a White bike, without a helmet.", | |
| # "Maithu riding a Red bike, with a helmet.", | |
| # "Maithu riding a Red bike, without a helmet.", | |
| # "Maithu riding a Black bike, with a helmet.", | |
| # "Maithu riding a Black bike, without a helmet.", | |
| # "Maithu riding a White bike, with a helmet.", | |
| # "Maithu riding a White bike, without a helmet."] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment