Dear people, as you may already know we transcend to the Rails5 era! Rails 5 required a Ruby upgrade so, apart from the new Rails APIs, we jumped from Ruby 2.3.8 to 2.6.3!
Apart from many performance improvements with less memory consumption, this gives us several goodies we can use from now on.
brew install libidn
rvm install ruby-2.6.3
sudo gem update --system 2.6.3
gem install bundler:2.0.2
bundle
GitHub upgraded to Ruby 2.6 and saw a 3% decrease in post boot memory usage. Direct instruction marking in Ruby 2.6 - The GitHub Blog
- Enumerable chain
e = (1..3).chain([4, 5])
e.to_a #=> [1, 2, 3, 4, 5]
- We can use
yield_self
orthen
!
construct_url
.yield_self { |url| Faraday.get(url) }.body
.yield_self { |response| JSON.parse(response) }
.dig('object', 'id')
.then { |id| id || '<undefined>' }
.then { |id| "server:#{id}" }
- Support pattern in
any?
,all?
&none?
. It lets us do away with the syntactic noise incurred by opening a block.
strs.any? { |str| /aeiou/i }
strs.all? { |str| /aeiou/i }
nums.none? { |num| /aeiou/i }
- Endless ranges. There was no simple way in Ruby to write an endless loop with index.
# examples
ary[1..] # identical to ary[1..-1] without magical -1
(1..).each {|index| ... } # enumerates values starting from index 1
ary.zip(1..) {|elem, index| ... } # ary.each.with_index(1) { ... }
- Function composition operators
f = proc{|x| x + 2}
g = proc{|x| x * 3}
(f << g).call(3) # -> 11; identical to f(g(3))
(f >> g).call(3) # -> 15; identical to g(f(3))
You can find a more elaborate analysis here:
- https://www.ruby-lang.org/en/news/2016/12/25/ruby-2-4-0-released/
- https://www.ruby-lang.org/en/news/2017/12/25/ruby-2-5-0-released/
- https://www.ruby-lang.org/en/news/2018/12/25/ruby-2-6-0-released/
#workable