This isn’t completely new functionality as this has always been available through the securerandom module.
require 'securerandom'
SecureRandom.bytes(10)
Why bother with this new method then?
Random.bytes trades security for speed, it’s 8x faster than SecureRandom.
Range#%
A new % method has been added to Range in Ruby 2.6.
Example:
((0..) % 2).take(5)
# [0, 2, 4, 6, 8]
This method is equivalent to Range#step.
TracePoint#parameters
The TracePoint class helps you trace events like method calls, class definitions & threads.
Ruby 2.6 adds a new parameters method.
With this new method you can print the parameter list for the method being called.
Example:
TracePoint.trace(:call, :b_call, :c_call) do |tp|
p [tp.event, tp.parameters]
end
def orange(a,b,c*)
end
orange(1,2,3)
Results in:
[:call, [[:req, :a], [:req, :b], [:rest, :c]]]
Transient Heap
The transient heap is a performance improvement for short-lived objects that aims to reduce the problem of memory fragmentation & slow calls to malloc.
Malloc is how the Ruby interpreter (and most C programs) request memory from the operating system.
According to the NEWS entry, we are looking at a 6-7% speedup.
Ruby 2.6 is coming with new useful features to help you write better code in less time. Another new performance-related feature, MJIT (Method Based Just-in-TIme Compiler) will be covered in a dedicated article.
Ruby 2.6 is expected to be released in December 25, 2018.
If you want to keep up with the changes, improve your Ruby skills & become an awesome Ruby developer don’t forget to join my Ruby newsletter today.
Thanks for reading!
Related
12 comments
Fernando Vieira says
4 years ago
Thank you for digesting it for us in an easy to read version!
Merry Christmas to us! I haven’t had a chance to stay up to day on the upcoming Ruby releases, so this was a nice quick read to help catch up. The new TracePoint params update looks to be interesting since I have been trying to work on my own open source performance tool. Will have to see where that fits in. Thanks for the post!