From: "cheba (Alexander Mankuta) via ruby-core" Date: 2025-11-17T18:29:31+00:00 Subject: [ruby-core:123833] [Ruby Bug#21693] Allow calling any callable object as a method Issue #21693 has been reported by cheba (Alexander Mankuta). ---------------------------------------- Bug #21693: Allow calling any callable object as a method https://bugs.ruby-lang.org/issues/21693 * Author: cheba (Alexander Mankuta) * Status: Open * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- 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/