|
|
|
|
|
by burlesona
1949 days ago
|
|
You can literally write my_method = Kernel.method(:puts) and it’ll give you the method to do what you wish with. As far as defining anonymous functions, literally all you have to do is: my_func = -> (input) { output } That makes a “lambda” which is literally just a function you can pass around anonymously. You call it via either my_func.call(input) or simply my_func[input]. That capability is used all over the place. Ruby absolutely has first class functions, the only thing you can say is it the syntax is slightly different if you want to use them anonymously (with no object context). |
|
That's exactly what being first-class is not. You tell Kernel to wrap you a method called puts into an object of class Method, rather than assigning a method to a variable. You don't have to look further than JS for a counterexample.