Skip to content

Instantly share code, notes, and snippets.

@banister
Created January 21, 2012 22:39
Show Gist options
  • Save banister/f3dadac6d1d730c09c8b to your computer and use it in GitHub Desktop.
Save banister/f3dadac6d1d730c09c8b to your computer and use it in GitHub Desktop.
Array.new(8) { [rand(10)] * 8 }
# => [[5, 5, 5, 5, 5, 5, 5, 5],
# [7, 7, 7, 7, 7, 7, 7, 7],
# [4, 4, 4, 4, 4, 4, 4, 4],
# [9, 9, 9, 9, 9, 9, 9, 9],
# [4, 4, 4, 4, 4, 4, 4, 4],
# [10, 10, 10, 10, 10, 10, 10, 10],
# [5, 5, 5, 5, 5, 5, 5, 5],
# [6, 6, 6, 6, 6, 6, 6, 6]]
a.map! { |v| v.map! { |t| t + 1 } }
# => [[5, 5, 5, 5, 5, 5, 5, 5],
# [7, 7, 7, 7, 7, 7, 7, 7],
# [4, 4, 4, 4, 4, 4, 4, 4],
# [9, 9, 9, 9, 9, 9, 9, 9],
# [4, 4, 4, 4, 4, 4, 4, 4],
# [10, 10, 10, 10, 10, 10, 10, 10],
# [5, 5, 5, 5, 5, 5, 5, 5],
# [6, 6, 6, 6, 6, 6, 6, 6]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment