From: "Eregon (Benoit Daloze) via ruby-core" Date: 2025-11-18T17:36:48+00:00 Subject: [ruby-core:123851] [Ruby Feature#21693] Allow calling any callable object as a method Issue #21693 has been updated by Eregon (Benoit Daloze). It would be a gigantic incompatibility so there is no chance for that specific syntax, as your example would call method `hello` before and no longer with your proposal. Just ```ruby p = 42 p(43) ``` would break for example with that change. ---------------------------------------- Feature #21693: Allow calling any callable object as a method https://bugs.ruby-lang.org/issues/21693#change-115249 * Author: cheba (Alexander Mankuta) * Status: Open ---------------------------------------- Callable objects are popular in Ruby. A very common pattern of Service objects with a single public `call` method can be found in many Rails apps, too. I propose to extend syntax so that adding `()` to any object that has a `call` method to work as a method invocation. Example: ```ruby class Greeter def call(name) puts "Hello, #{name}!" end end hello = Greeter.new hello("World") # => Hello, World! ``` We have a `[]` method in `Proc` that achieves similar effect but it doesn't look like a method call. There's also a dotted syntax `hello.("World")` but it also looks a little awkward and the dot is easy to forget. It's probably a bit late for Ruby 4, but I though it's a good opportunity to introduce a potentially big change. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/