Skip to content

Instantly share code, notes, and snippets.

@jfcalvo
Created August 31, 2011 06:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfcalvo/1182935 to your computer and use it in GitHub Desktop.
Save jfcalvo/1182935 to your computer and use it in GitHub Desktop.
Ruby block example using each_with_index and inject at the same time.
[1, 2, 3, 4].each_with_index.inject(0) do | memo, (number, i) |
puts "number: #{number}, i: #{i}."
puts "memo: #{memo}."
memo += number
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment