Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created May 5, 2010 13:07
Show Gist options
  • Save workmad3/390740 to your computer and use it in GitHub Desktop.
Save workmad3/390740 to your computer and use it in GitHub Desktop.
def add_n(n)
Proc.new {|x| x + n }
end
add_5 = add_n(5)
add_5.call(1)
add_5.call(7)
add_10 = add_n(10)
add_10.call(add_5.call(4))
def accumulator
start = 0
Proc.new { start += 1 }
end
acc1 = accumulator
acc1.call()
acc1.call()
acc1.call
acc2 = accumulator
acc2.call()
acc1.call()
acc2.call()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment