saasbook

each_with_index.rb

May 1st, 2012
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.17 KB | None | 0 0
  1. include Enumerable
  2. %w(alice bob carol).each_with_index do |person,index|
  3.   puts ">> #{person} is number #{index}"
  4. end
  5. >> alice is number 0
  6. >> bob is number 1
  7. >> carol is number 2
Advertisement
Add Comment
Please, Sign In to add comment