Last active
December 3, 2015 01:47
-
-
Save daiando/0151255078825e05d006 to your computer and use it in GitHub Desktop.
[ ruby ] each_with_index のサンプル ref: http://qiita.com/penguin_dream/items/81dedfb4aed6a4d847c4
This file contains 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
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"] |
This file contains 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
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