Skip to content

Instantly share code, notes, and snippets.

@sheenobu
Created November 1, 2012 19:02
Show Gist options
  • Save sheenobu/3995738 to your computer and use it in GitHub Desktop.
Save sheenobu/3995738 to your computer and use it in GitHub Desktop.
Create N lists by unzipping a the results of map.
even_numbers,odd_numbers,starts_with_one = entire = (1..10).map do |x|
[ (x if x % 2 == 0) ,(x if x % 2 != 0), (x if x.to_s[0] == '1') ]
end.transpose.map { |x| x.compact }
# The entities within the map [ ..., ..., ..N] end up in their respective list
# variables. compact is for removing nils from the resulting nested lists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment