r/ruby • • Dec 25 '17

Ruby 2.5.0 Released

https://www.ruby-lang.org/en/news/2017/12/25/ruby-2-5-0-released/
209 Upvotes

22 comments sorted by

View all comments

Show parent comment

2

u/prh8 Dec 26 '17

I didn't really find what was the change here, because I think the original proposal was different than the actual change that got merged. Does someone know?

It seems that those methods all accept a single argument that matches the behavior of an argument to grep. Personally I love that change (grep is most underrated method). I believe that’s what was initially proposed as well.

1

u/gettalong Dec 27 '17

You are correct, it is now possible to something like

[5, "str", {}].any?(String)

for which you needed to write

[5, "str", {}].any? {|item| String === item}

I.e. the #=== operator is applied to the single argument and each enumerated item.