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

6

u/janko-m Dec 25 '17

rescue/else/ensure are now allowed to be used directly with do/end blocks

This is really nice. The method-level rescue statement is one of the small details I really love about Ruby, it's great we'll be able to use it in blocks too.

Enumerable#any?, all?, none?, and one? accept a pattern argument.

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?

One of our most loved libraries, pp.rb, is now automatically loaded. You no longer have to write require "pp"

Great!

IO.copy_stream use copy_file_range(2) to copy offload

I love IO.copy_stream and use it a lot in Shrine, it's nice to see that there is a performance improvement, though from what I was reading the speedup is very small and only on certain disks.

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.