Skip to content

Instantly share code, notes, and snippets.

@paneq
Created April 28, 2011 12:59
Show Gist options
  • Save paneq/946294 to your computer and use it in GitHub Desktop.
Save paneq/946294 to your computer and use it in GitHub Desktop.
Creating nested procs with inject
inside = Proc.new{ puts 'inside' }
nested = [1,2,3].reverse.inject(inside) do |sum, obj|
Proc.new do |&inner|
puts obj
sum.call(&inner)
puts obj
end
end
nested.call()
1
2
3
inside
3
2
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment