3 ms·
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.
by ezekg 3y ago
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.
- josevalim 3y agoAnd 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