test.rb:
def do_stuff(binary_function) 2.send(binary_function, 3) end p do_stuff(:+) p do_stuff(:*)
$ ruby ββtest.rb
5
6
If you pass the method name as a character, it can be called via send. This is what injections and friends do.
About || if the left side returns nil or false, lhs || 1 lhs || 1 will return 1
source share