Symbol#to_proc and Ruby’s Open Classes

Just saw an article related to my last post about Symbol#to_proc. Very interesting read! And even more fun is this article which explains the same mechanism and currying on top:

proc {|x, y, z| x + y + z }.curry

returns the equivalent of:

proc {|x| proc {|y| proc {|z| x + y + z } } }

Here’s the example:

plus_five = proc { |x,y,z| x + y + z }.curry.call(2).call(3)
plus_five[10]  #=> 15

I’ve seen something similar in Scala. A good explanation of Scala function currying can be found in Daniel Spiewak’s blog. BTW, Scala finally got a new website! And even better: Just got an E-Mail from Artima.com that the 4th edition of “Programming in Scala” arrived. Something to read for the weekend!