Ruby array collect with index


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # returns: ["0: a", "1: b", "2: c"]
  2. %w(a b c).enum_for(:each_with_index).collect { |o, i| "#{i}: #{o}" }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.