Ruby 2.7.0 Released

11 months ago - Direct link

We are pleased to announce the release of Ruby 2.7.0.

It introduces a number of new features and performance improvements,
most notably:


  • Pattern Matching

  • REPL improvement

  • Compaction GC

  • Separation of positional and keyword arguments

Pattern Matching [Experimental]

Pattern matching, a widely used feature in functional programming languages,
is introduced as an experimental feature.
[Feature #14912]

It can traverse a given object and assign its value if it matches a pattern.

require "json"

json = <<END
{
"name": "Alice",
"age": 30,
"children": [{ "name": "Bob", "age": 2 }]
}
END

case JSON.parse(json, symbolize_names: true)
in {name: "Alice", children: [{name: "Bob", age: age}]}
p age #=> 2
end

For more details, please see
...


Go to article →

Links in this thread

Feature #14912: Introduce pattern matching syntax - Ruby master - Ruby Issue Tracking System
Redmine


Pattern matching - New feature in Ruby 2.7
https://rubykaigi.org/2019/presentations/k_tsj.html


Feature #14683: IRB with Ripper - Ruby master - Ruby Issue Tracking System
Redmine


Feature #14787: Show documents when completion - Ruby master - Ruby Issue Tracking System
Redmine


Bug #14918: Use Reline for fallback of ext/readline - Ruby master - Ruby Issue Tracking System
Redmine


Feature #15626: Manual Compaction for MRI's GC (`GC.compact`) - Ruby master - Ruby Issue Tracking System
Redmine


Feature #14183: "Real" keyword argument - Ruby master - Ruby Issue Tracking System
Redmine


Separation of positional and keyword arguments in Ruby 3.0
In Ruby 3.0, positional arguments and keyword arguments will be separated. Ruby 2.7 will warn for behaviors that will change in Ruby 3.0. If you see the following warnings, you need to update your code:


Feature #4475: default variable name for parameter - Ruby master - Ruby Issue Tracking System
Redmine


Feature #14799: Startless range - Ruby master - Ruby Issue Tracking System
Redmine


Feature #11297: Allow private method of self to be called - Ruby master - Ruby Issue Tracking System
Redmine


Feature #16123: Allow calling a private method with `self.` - Ruby master - Ruby Issue Tracking System
Redmine


Feature #15901: Enumerator::Lazy#eager - Ruby master - Ruby Issue Tracking System
Redmine


Improve performance of fiber creation by using pool allocation strategy. by ioquatix · Pull Request #2224 · ruby/ruby
https://bugs.ruby-lang.org/issues/15997 It would be good to get some feedback on this PR. $ make benchmark ITEM=fiber COMPARE_RUBY="../build-master/ruby" Calculating ------------------------------------- compare-ruby built-ruby make_chain 77.840 73.809 i/s - 500.000 times in 6.423414s 6.774286s resume_chain 161.783 168.189 i/s - 500.000 times in 3.090556s 2.972852s vm2_fiber_allocate 68.114k 112.117k i/s - 200.000k times in 2.936240s 1.783851s vm2_fiber_switch 7.812M 8.295M i/s - 10.000M times in 1.280088s 1.205587s Comparison: make_chain compare-ruby: 77.8 i/s built-ruby: 73.8 i/s - 1.05x slower ** n/c within margin of error resume_chain built-ruby: 168.2 i/s compare-ruby: 161.8 i/s - 1.04x slower ** n/c within margin of error vm2_fiber_allocate built-ruby: 112117.0 i/s compare-ruby: 68114.3 i/s - 1.65x slower ** significant improvement vm2_fiber_switch built-ruby: 8294714.5 i/s compare-ruby: 7811962.9 i/s - 1.06x slower ** n/c within margin of error


Feature #16150: Add a way to request a frozen string from to_s - Ruby master - Ruby Issue Tracking System
Redmine


Optimize CGI.escapeHTML by reducing buffer extension and branches by k0kubun · Pull Request #2226 · ruby/ruby
Benchmark Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores, gcc 7.3.0 escape_utils.gem's benchmark Here's the benchmark result of escape_utils/benchmark/html_escape.rb using this CGI.escapeHTML. Originally CGI.escapeHTML was about 0.72x of EscapeUtils.escape_html, and now it's 2.48x. $ bundle exec ruby -v benchmark/html_escape.rb ruby 2.7.0dev (2019-06-05 master 0a29dc8) [x86_64-linux] last_commit=Optimize CGI.escapeHTML by reducing buffer extension Escaping 154483 bytes of html from https://en.wikipedia.org/wiki/Succession_to_the_British_throne Warming up -------------------------------------- Rack::Utils.escape_html 16.000 i/100ms Haml::Helpers.html_escape 616.000 i/100ms ERB::Util.html_escape 626.000 i/100ms CGI.escapeHTML 631.000 i/100ms String#gsub 24.000 i/100ms fast_xs_extra#fast_xs_html 332.000 i/100ms EscapeUtils.escape_html 255.000 i/100ms Calculating ------------------------------------- Rack::Utils.escape_html 166.291 (± 2.4%) i/s - 832.000 in 5.006558s Haml::Helpers.html_escape 6.376k (± 2.7%) i/s - 32.032k in 5.028389s ERB::Util.html_escape 6.366k (± 3.6%) i/s - 31.926k in 5.022500s CGI.escapeHTML 6.386k (± 3.1%) i/s - 32.181k in 5.045185s String#gsub 240.854 (± 1.2%) i/s - 1.224k in 5.082920s fast_xs_extra#fast_xs_html 3.345k (± 1.8%) i/s - 16.932k in 5.064190s EscapeUtils.escape_html 2.572k (± 3.0%) i/s - 13.005k in 5.060726s Comparison: CGI.escapeHTML: 6385.6 i/s Haml::Helpers.html_escape: 6375.6 i/s - same-ish: difference falls within error ERB::Util.html_escape: 6366.2 i/s - same-ish: difference falls within error fast_xs_extra#fast_xs_html: 3344.6 i/s - 1.91x slower EscapeUtils.escape_html: 2572.2 i/s - 2.48x slower String#gsub: 240.9 i/s - 26.51x slower Rack::Utils.escape_html: 166.3 i/s - 38.40x slower Note: Haml::Helpers.html_escape uses ERB::Util.html_escape which uses CGI.escapeHTML, so those 3 are the same. Other scenarios When there's at least one escaped character (_one, _all, _real), it becomes 1.91~5.35x. When there's nothing to be escaped (_blank, _none), unfortunately it becomes 1.08~1.12x slower. $ benchmark-driver benchmark/cgi_escape_html.yml -v --rbenv 'before;after' --repeat-count=8 before: ruby 2.7.0dev (2019-06-05 master f3c877e) [x86_64-linux] after: ruby 2.7.0dev (2019-06-05 master 0a29dc8) [x86_64-linux] last_commit=Optimize CGI.escapeHTML by reducing buffer extension Calculating ------------------------------------- before after escape_html_blank 26.946M 25.011M i/s - 20.000M times in 0.742213s 0.799655s escape_html_short_none 25.898M 23.174M i/s - 20.000M times in 0.772249s 0.863042s escape_html_short_one 8.046M 17.748M i/s - 20.000M times in 2.485578s 1.126892s escape_html_short_all 5.539M 10.561M i/s - 5.000M times in 0.902758s 0.473462s escape_html_long_none 1.373M 1.231M i/s - 1.000M times in 0.728400s 0.812565s escape_html_long_all 1.093M 5.849M i/s - 1.000M times in 0.914765s 0.170957s escape_html_real 1.121M 2.565M i/s - 1.000M times in 0.891941s 0.389921s Comparison: escape_html_blank before: 26946437.8 i/s after: 25010784.2 i/s - 1.08x slower escape_html_short_none before: 25898374.9 i/s after: 23173849.3 i/s - 1.12x slower escape_html_short_one after: 17747937.4 i/s before: 8046417.1 i/s - 2.21x slower escape_html_short_all after: 10560503.5 i/s before: 5538580.2 i/s - 1.91x slower escape_html_long_none before: 1372873.0 i/s after: 1230671.0 i/s - 1.12x slower escape_html_long_all after: 5849414.4 i/s before: 1093177.0 i/s - 5.35x slower escape_html_real after: 2564622.4 i/s before: 1121150.9 i/s - 2.29x slower


Feature #16255: Make `monitor.rb` built-in - Ruby master - Ruby Issue Tracking System
Redmine


reduce cache mishits by shyouhei · Pull Request #2583 · ruby/ruby
While running discourse benchmark under linux perf, I noticed one of the most frequent operations that ruby does is the method lookup. That was kind of known, but something didn't smell right. I pushed 3ffd98c and ran the benchmark again, to get this output: So 65,039,079 out of 94,613,117 inline cache mishits are spurious; they resulted in method lookups that end up exactly the same method entry the cache already stored. This is not a buggy behaviour and your program works as expected (apart from unnecessarily consuming our precious environmental resources to generate electricity for the computation). However there definitely is a room of improvements. Let's use the cache more efficiently. We are facing the fact that several classes share the identical method entry for a method name; possibly due to inheritance, inclusions, and so on. We can use this. A call cache is valid for multiple classes. So in order to express the info, this changeset expands struct rb_call_cache from 44-ish bytes to cache line width. The space we add is used for second and later class serials. By this changeset the debug counter output for the same benchmark is now like this: The mc_miss_spurious counter dropped down to 23,344,738.


Release v2.1.2 · rubygems/bundler
Manage your Ruby application's gem dependencies. Contribute to rubygems/bundler development by creating an account on GitHub.


Release v3.1.0 · rubygems/rubygems
Library packaging and distribution for Ruby. Contribute to rubygems/rubygems development by creating an account on GitHub.


Release v3.1.1 · rubygems/rubygems
Library packaging and distribution for Ruby. Contribute to rubygems/rubygems development by creating an account on GitHub.


Release v3.1.2 · rubygems/rubygems
Library packaging and distribution for Ruby. Contribute to rubygems/rubygems development by creating an account on GitHub.


ruby/csv
CSV Reading and Writing. Contribute to ruby/csv development by creating an account on GitHub.


ruby/rexml
REXML is an XML toolkit for Ruby. Contribute to ruby/rexml development by creating an account on GitHub.


ruby/rss
RSS reading and writing. Contribute to ruby/rss development by creating an account on GitHub.


Feature #15321: Update Unicode data to Unicode Version 12.0.0 - Ruby master - Ruby Issue Tracking System
Redmine


Feature #15195: Deal with new Japanese era - Ruby master - Ruby Issue Tracking System
Redmine


Feature #15742: Add Date#jisx0301 support new Japanese era - Ruby master - Ruby Issue Tracking System
Redmine


Misc #15347: Require C99 - Ruby master - Ruby Issue Tracking System
Redmine


C99 - Ruby master - Ruby Issue Tracking System
Redmine


ruby/ruby
The Ruby Programming Language [mirror]. Contribute to ruby/ruby development by creating an account on GitHub.


https://github.com/ruby/ruby/compare/v2_6_0...v2_7_0


https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.bz2


https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.gz


https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.xz


https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.zip