2 ms·
Yes, that would be: method = o.method(:my_method) method.call(5) # or method[5], or method.(5) If you really want a "function" that you can call w
by catwell 5y ago
Yes, that would be:
method = o.method(:my_method)
method.call(5)
# or method[5], or method.(5)
If you really want a "function" that you can call with parens:
Kernel.define_method(:method_as_fun, &method)
(Definitely don't do that last bit in a real project...)
- jonnytran 5y agoAnd before someone criticizes Ruby for being inconsistent in how the method is called, Ruby isn't a callable oriented language [1]. The common case is calling methods, so the fact that you need to say `.call(5)` both makes it more consistent and makes real code more concise, especially when making DSLs where chaining is really useful. 1: https://yehudakatz.com/2010/02/21/ruby-is-not-a-callable-oriented-language/ https://yehudakatz.com/2010/02/21/ruby-is-not-a-callable-ori...