Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is incorrect. If you want an anonymous function (with no object context) you can write a lambda, store it to a value, make other lambdas that call it and return yet another lambda etc.

You can do the exact same thing with object methods if you want, eg. my_puts = Kernel.method(:puts).

You can even do this in one line and stop the auto parenthesis behavior if you want.

foo = method def foo ... end

Now foo will reference the method and you have to use foo() to call it.

The reason that people don’t do a bunch of that in Ruby is that the support for anonymous blocks is so convenient That there aren’t that many cases where you really need anonymous functions detached from any object.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: