method
enum_for
![Wide documentation Importance_3](https://d2vfyqvduarcvs.cloudfront.net/images/importance_3.png?1349367920)
enum_for(...)
public
Register or
log in
to add new notes.
yonosoytu -
August 23, 2008
rob-twf -
May 27, 2009 - (>= v1_8_6_287)
![Default_avatar_30](https://www.gravatar.com/avatar/49b6123803e4f327144e991daab62f77?default=http://apidock.com/images/default_avatar_30.png&size=30)
4 thanks
Needs requiring 'enumerator' to work
This method needs that you
require 'enumerator'
for this method to be available.
![Default_avatar_30](https://www.gravatar.com/avatar/175b1b15a0ae5a8a690479641ad8ac5a?default=http://apidock.com/images/default_avatar_30.png&size=30)
3 thanks
map_with_index
If you want to access the element index when using map, you can do it with enum_for:
(1..6).enum_for(:each_with_index).map { |v, i| "index: #{i} value: #{v}" } #=> ["index: 0 value: 1", "index: 1 value: 2", "index: 2 value: 3", "index: 3 value: 4", "index: 4 value: 5", "index: 5 value: 6"]