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

You can do the same thing in Ruby, although I think it's cursed:

    fn = -> x { puts "hello #{x}" }
    fn.('world')
In Ruby, .() is an alias to #call.


And because in Ruby it is a shortcut, you can invoke it on any object:

    irb(main):008:0> class Integer
    irb(main):009:1> def call(b); self.+(b) end
    irb(main):010:1> end
    => :call
    irb(main):011:0> 1.(2)
    => 3
:D




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

Search: