DEV Community

Reverted Ruby 2.7 new feature: Method reference operator

Seiei Miyagi on January 05, 2019

2019/11/12 reverted πŸ‘‹ https://github.com/ruby/ruby/commit/fb6a489af2765a3b56e301adf0019af6bbad6156 https://bugs.ruby-lang.org/issues/16...
Collapse
 
igorkasyanchuk profile image
Igor Kasyanchuk • Edited
["NG"].any?(&"COPYING".:include?)

I really believe Ruby is moving in the wrong direction. This is not readable.

Collapse
 
hanachin profile image
Seiei Miyagi

That's my example's problem.

Many other real world use-cases are on the issues.
bugs.ruby-lang.org/issues/12125
bugs.ruby-lang.org/issues/13581

It's handy in block argument for Enumerable methods like map, or select.

Collapse
 
ben profile image
Ben Halpern

At first glance this seems a bit voodoo magic compared with the more explicit method, but the more I look at it, the more it does seem to be intuitive compared with other places : is used as a prefix in similar ways in Ruby.

Nice little upcoming addition.

Collapse
 
codeandclay profile image
Oliver

The commit says the operator is introduced as an experimental feature. What does experimental mean in this case? Am I right in understanding that because 2.7 is only in preview, the operator is not guaranteed to make it to the final release?

Collapse
 
hanachin profile image
Seiei Miyagi

My understanding is, experimental mean the behavior may change in future versions of Ruby. We can try experimental features and give a feedback to ruby-core team.
There is a release note about the refinements which was experimental feature in ruby 2.0.

However, please be aware that Refinements is still an experimental feature: we may change its specification in the future. Despite that, we would like you to play with it and give us your thoughts. Your feedback will help to forge this interesting feature.
ruby-lang.org/en/news/2013/02/24/r...

Collapse
 
hanachin profile image
Seiei Miyagi

Updated the code, Thanks for improvements!

Collapse
 
tomlord profile image
Tom Lord

I don't like this syntax, at all.

It shaves off a few characters, but massively damages readability.

How is a new developer to make sense of this syntax? One thing ruby is really good at is "reading like English"; but this syntax appears more optimised for code golf than for human understanding.

Collapse
 
hanachin profile image
Seiei Miyagi

In other programming languages, they have more convenient way to reference the method.

gist.github.com/americodls/20981b2...
bugs.ruby-lang.org/issues/13581

IMO, the difference between Ruby and other languages is method calling.
Other languages can reference the method by .method_name without (), but ruby can't because Ruby doesn't need () for method call.

The .: looks like method calling ., with additional : can reference the method. That makes sense to me.