From: Gary Wright Date: 2011-01-20T05:58:46+09:00 Subject: [ruby-core:34616] Re: [Ruby 1.9-Feature#4288][Open] Allow invoking arbitrary method names with foo."something" syntax On Jan 18, 2011, at 12:51 AM, Charles Nutter wrote: > For non-standard or arbitrary method names, it would be nice to have a way to invoke them directly that doesn't require the parser to be made more complex nor require an intermediate "send" call. Groovy does this by allowing the following form: > > foo."asdf"() > > This syntax would make it easier to integrate with other languages that have different naming rules. For example, =!@+= is a valid operator in Scala. With this syntax, you could invoke it as Maybe I'm crazy, but could I suggest something a little more general? foo.{expression}(arg1) to have the same semantics as foo.send(expression, arg1) Charles' example would then become: foo.{"asdf"}() or more likely if the code was being generated automatically foo.{some_variable}() If string interpolation was available then Charles' proposed syntax would allow dynamic dispatch via: foo."#{some_variable}"() which has the same generality as my proposed syntax but with some extra line noise. I've always found the use of Kernel#send for dynamic method dispatch to be a bit awkward and would prefer something that was syntactically similar to static method dispatch rather than the current dependency on the 'magic' behavior of Kernel#send. Perhaps a syntactic approach to dynamic dispatch would enable more interesting optimizations since it would be clear that something 'interesting' was going on rather than just a generic method call to a magic method like Kernel#send. Gary Wright