Skip to content

Instantly share code, notes, and snippets.

@daiando
Last active December 3, 2015 01:47
Show Gist options
  • Save daiando/0151255078825e05d006 to your computer and use it in GitHub Desktop.
Save daiando/0151255078825e05d006 to your computer and use it in GitHub Desktop.
[ ruby ] each_with_index のサンプル ref: http://qiita.com/penguin_dream/items/81dedfb4aed6a4d847c4
array = []
sample = %w(a b c d e)
sample.each_with_index { |item, index| array[index] = "#{index}:#{item}" }
p array
=> ["0:a","1:b","2:c","3:d","4:e"]
array = []
sample = %w(a b c d e)
sample.each_with_index { |item, index| array[index] = "#{index}:#{item}" }
p array
=> ["0:a","1:b","2:c","3:d","4:e"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment