CINXE.COM

Ruby 3.1.0 Released

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Ruby 3.1.0 Released</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta itemprop="image" content="https://www.ruby-lang.org/images/header-ruby-logo@2x.png"> <meta name="description" content=""> <link rel="stylesheet" type="text/css" href="/stylesheets/normalize.css"> <link rel="stylesheet" type="text/css" href="/stylesheets/main.css"> <link rel="stylesheet" type="text/css" href="/stylesheets/pygments.css"> <link rel="stylesheet" type="text/css" href="/stylesheets/mobile.css"> <link rel="stylesheet" type="text/css" href="/stylesheets/print.css"> <link href='https://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic,700italic&amp;subset=latin,cyrillic,greek,vietnamese' rel='stylesheet' type='text/css'> <link rel="canonical" href="https://www.ruby-lang.org/en/news/2021/12/25/ruby-3-1-0-released/"> <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"> <link href="/en/feeds/news.rss" rel="alternate" title="Recent News (RSS)" type="application/rss+xml"> <script type="text/javascript" src="/javascripts/jquery.min.js"></script> <script type="text/javascript" src="/javascripts/page.js"></script> </head> <body> <div id="header"> <div id="header_content" class="container"> <a href="/en/"> <h1>Ruby</h1> <h2>A Programmer's Best Friend</h2> </a> <div class="site-links"> <a href="/en/" class="home">Home</a> <a href="/en/downloads/">Downloads</a> <a href="/en/documentation/">Documentation</a> <a href="/en/libraries/">Libraries</a> <a href="/en/community/">Community</a> <a href="/en/news/">News</a> <a href="/en/security/">Security</a> <a href="/en/about/">About Ruby</a> <a href="#" class="menu selected">Menu</a> </div> <div id="search-box"> <form id="search-form" action="https://www.google.com/cse"> <table class="fieldset"> <tr> <td> <input class="field" type="text" name="q" size="31" style="background: white url(//www.google.com/coop/intl/en/images/google_custom_search_watermark.gif) left no-repeat" onfocus="this.style.background='white'" onblur="if (/^\s*$/.test(this.value)) this.style.background='white url(//www.google.com/coop/intl/en/images/google_custom_search_watermark.gif) left no-repeat'"/> </td> <td> <input type="hidden" name="cx" value="013598269713424429640:g5orptiw95w" /> <input type="hidden" name="ie" value="UTF-8" /> <input class="button" type="submit" name="sa" value="Search" /> </td> </tr> </table> </form> </div> </div> </div> <div id="page"> <div id="main-wrapper" class="container"> <div id="main"> <div id="content-wrapper"> <h1>Ruby 3.1.0 Released</h1> <div id="content"> <p class="post-info">Posted by naruse on 25 Dec 2021</p> <p>We are pleased to announce the release of Ruby 3.1.0. Ruby 3.1 keeps compatibility with Ruby 3.0 and also adds many features.</p> <h2>YJIT: New experimental in-process JIT compiler</h2> <p>Ruby 3.1 merges YJIT, a new in-process JIT compiler developed by Shopify.</p> <p>Since <a href="https://www.ruby-lang.org/en/news/2018/12/25/ruby-2-6-0-released/">Ruby 2.6 introduced MJIT in 2018</a>, its performance greatly improved, and finally <a href="https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/">we achieved Ruby3x3 last year</a>. But even though the Optcarrot benchmark has shown impressive speedups, the JIT has not benefited real world business applications.</p> <p>Recently Shopify contributed many Ruby improvements to speed up their Rails application. YJIT is an important contribution, and aims to improve the performance of Rails applications.</p> <p>While MJIT is a method-based JIT compiler and uses an external C compiler, YJIT uses Basic Block Versioning and includes a JIT compiler inside it. With Lazy Basic Block Versioning (LBBV) it first compiles the beginning of a method, and incrementally compiles the rest when the type of arguments and variables are dynamically determined. See <a href="https://dl.acm.org/doi/10.1145/3486606.3486781">YJIT: a basic block versioning JIT compiler for CRuby</a> for a detailed introduction.</p> <p>With this technology, YJIT achieves both fast warmup time and performance improvements on most real-world software, up to 22% on railsbench, 39% on liquid-render.</p> <p>YJIT is still an experimental feature, and as such, it is disabled by default. If you want to use this, specify the <code class="language-plaintext highlighter-rouge">--yjit</code> command-line option to enable YJIT. It is also limited to Unix-like x86-64 platforms for now.</p> <ul> <li><a href="https://bugs.ruby-lang.org/issues/18229">https://bugs.ruby-lang.org/issues/18229</a></li> <li><a href="https://shopify.engineering/yjit-just-in-time-compiler-cruby">https://shopify.engineering/yjit-just-in-time-compiler-cruby</a></li> <li><a href="https://www.youtube.com/watch?v=PBVLf3yfMs8">https://www.youtube.com/watch?v=PBVLf3yfMs8</a></li> </ul> <h2>debug gem: A new debugger</h2> <p>A completely rewritten debugger <a href="https://github.com/ruby/debug">debug.gem</a> is bundled. debug.gem has the following features:</p> <ul> <li>Improve the debugging performance (it does not slow down the application even with the debugger).</li> <li>Support remote debugging.</li> <li>Support rich debugging frontend (VS Code and Chrome browser are supported currently).</li> <li>Support multi-process/multi-thread debugging.</li> <li>Colorful REPL.</li> <li>And other useful features like record &amp; replay feature, tracing feature and so on.</li> </ul> <video autoplay="autoplay" controls="controls" muted="muted" width="764" height="510" poster="https://cache.ruby-lang.org/pub/media/ruby310_debug_demo.jpg"> <source src="https://cache.ruby-lang.org/pub/media/ruby310_debug_demo.mp4" type="video/mp4" /> </video> <p>Ruby had bundled lib/debug.rb, but it was not well maintained and it had issues about performance and features. debug.gem replaces lib/debug.rb completely.</p> <h2>error_highlight: Fine-grained error location in backtrace</h2> <p>A built-in gem, error_highlight, has been introduced. It includes fine-grained error location in backtraces:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ ruby test.rb test.rb:1:in `&lt;main&gt;': undefined method `time' for 1:Integer (NoMethodError) 1.time {} ^^^^^ Did you mean? times </code></pre></div></div> <p>Currently, only <code class="language-plaintext highlighter-rouge">NameError</code> is supported.</p> <p>This gem is enabled by default. You can disable it by using the command-line option <code class="language-plaintext highlighter-rouge">--disable-error_highlight</code>. See the <a href="https://github.com/ruby/error_highlight">error_highlight repository</a> for details.</p> <h2>IRB Autocomplete and Documentation Display</h2> <p>The IRB now has an autocomplete feature, where you can just type in the code, and the completion candidates dialog will appear. You can use Tab and Shift+Tab to move up and down.</p> <p>If documentation is installed when you select a completion candidate, the documentation dialog will appear next to the completion candidates dialog, showing part of the content. You can read the full documentation by pressing Alt+d.</p> <video autoplay="autoplay" controls="controls" muted="muted" width="764" height="510" poster="https://cache.ruby-lang.org/pub/media/ruby310_irb_dialog.png"> <source src="https://cache.ruby-lang.org/pub/media/ruby310_irb_dialog.mp4" type="video/mp4" /> </video> <h2>Other Notable New Features</h2> <h3>Language</h3> <ul> <li>Values in Hash literals and keyword arguments can be omitted. <a href="https://bugs.ruby-lang.org/issues/14579">[Feature #14579]</a> <ul> <li><code class="language-plaintext highlighter-rouge">{x:, y:}</code> is syntax sugar for <code class="language-plaintext highlighter-rouge">{x: x, y: y}</code>.</li> <li><code class="language-plaintext highlighter-rouge">foo(x:, y:)</code> is syntax sugar for <code class="language-plaintext highlighter-rouge">foo(x: x, y: y)</code>.</li> </ul> </li> <li> <p>The pin operator (<code class="language-plaintext highlighter-rouge">^</code>) in pattern matching now takes an expression. <a href="https://bugs.ruby-lang.org/issues/17411">[Feature #17411]</a></p> <div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="no">Prime</span><span class="p">.</span><span class="nf">each_cons</span><span class="p">(</span><span class="mi">2</span><span class="p">).</span><span class="nf">lazy</span><span class="p">.</span><span class="nf">find_all</span><span class="p">{</span><span class="n">_1</span> <span class="k">in</span> <span class="p">[</span><span class="n">n</span><span class="p">,</span> <span class="o">^</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)]}.</span><span class="nf">take</span><span class="p">(</span><span class="mi">3</span><span class="p">).</span><span class="nf">to_a</span> <span class="c1">#=&gt; [[3, 5], [5, 7], [11, 13]]</span> </code></pre></div> </div> </li> <li> <p>Parentheses can be omitted in one-line pattern matching. <a href="https://bugs.ruby-lang.org/issues/16182">[Feature #16182]</a></p> <div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="n">_</span><span class="p">,</span> <span class="n">x</span> <span class="p">{</span><span class="ss">y: </span><span class="mi">2</span><span class="p">}</span> <span class="o">=&gt;</span> <span class="ss">y: </span><span class="n">x</span> <span class="c1">#=&gt; 1</span> <span class="n">y</span> <span class="c1">#=&gt; 2</span> </code></pre></div> </div> </li> </ul> <h3>RBS</h3> <p>RBS is a language to describe the structure of Ruby programs. See the <a href="https://github.com/ruby/rbs">RBS repository</a> for details.</p> <p>Updates since Ruby 3.0.0:</p> <ul> <li>Generic type parameters can be bounded. (<a href="https://github.com/ruby/rbs/pull/844">PR</a>)</li> <li>Generic type aliases are supported. (<a href="https://github.com/ruby/rbs/pull/823">PR</a>)</li> <li><code class="language-plaintext highlighter-rouge">rbs collection</code> has been introduced to manage gems’ RBSs. (<a href="https://github.com/ruby/rbs/blob/master/docs/collection.md">doc</a>)</li> <li>Many signatures for built-in and standard libraries have been added/updated.</li> <li>It includes many bug fixes and performance improvements too.</li> </ul> <p>See the <a href="https://github.com/ruby/rbs/blob/master/CHANGELOG.md">RBS changelog</a> for more information.</p> <h3>TypeProf</h3> <p>TypeProf is a static type analyzer for Ruby. It generates a prototype of RBS from non-type-annotated Ruby code. See the <a href="https://github.com/ruby/typeprof/blob/master/doc/doc.md">documentation</a> for details.</p> <p>The main update since Ruby 3.0.0 is an experimental IDE support called “TypeProf for IDE”.</p> <p><img src="https://cache.ruby-lang.org/pub/media/ruby310_typeprof_ide_demo.png" alt="Demo of TypeProf for IDE" /></p> <p>The VS Code extension shows a guessed (or explicitly written in an RBS file) method signature above each method definition, draws a red underline under the code that may cause a name error or type error, and completes method names (i.e., shows method candidates). See the <a href="https://github.com/ruby/typeprof/blob/master/doc/ide.md">documentation</a> for details.</p> <p>Also, the release includes many bug fixes and performance improvements.</p> <h2>Performance improvements</h2> <ul> <li>MJIT <ul> <li>For workloads like Rails, the default <code class="language-plaintext highlighter-rouge">--jit-max-cache</code> is changed from 100 to 10000. The JIT compiler no longer skips compilation of methods longer than 1000 instructions.</li> <li>To support Zeitwerk of Rails, JIT-ed code is no longer cancelled when a TracePoint for class events is enabled.</li> </ul> </li> </ul> <h2>Other notable changes since 3.0</h2> <ul> <li>One-line pattern matching, e.g., <code class="language-plaintext highlighter-rouge">ary =&gt; [x, y, z]</code>, is no longer experimental.</li> <li>Multiple assignment evaluation order has been changed slightly. <a href="https://bugs.ruby-lang.org/issues/4443">[Bug #4443]</a> <ul> <li><code class="language-plaintext highlighter-rouge">foo[0], bar[0] = baz, qux</code> was evaluated in order <code class="language-plaintext highlighter-rouge">baz</code>, <code class="language-plaintext highlighter-rouge">qux</code>, <code class="language-plaintext highlighter-rouge">foo</code>, and then <code class="language-plaintext highlighter-rouge">bar</code> in Ruby 3.0. In Ruby 3.1, it is evaluated in order <code class="language-plaintext highlighter-rouge">foo</code>, <code class="language-plaintext highlighter-rouge">bar</code>, <code class="language-plaintext highlighter-rouge">baz</code>, and then <code class="language-plaintext highlighter-rouge">qux</code>.</li> </ul> </li> <li> <p>Variable Width Allocation: Strings (experimental). <a href="https://bugs.ruby-lang.org/issues/18239">[Bug #18239]</a></p> </li> <li>Psych 4.0 changes <code class="language-plaintext highlighter-rouge">Psych.load</code> to use <code class="language-plaintext highlighter-rouge">safe_load</code> by default. You may need to use Psych 3.3.2 for migrating to this behavior. <a href="https://bugs.ruby-lang.org/issues/17866">[Bug #17866]</a></li> </ul> <h3>Standard libraries updates</h3> <ul> <li>The following default gems are updated. <ul> <li>RubyGems 3.3.3</li> <li>base64 0.1.1</li> <li>benchmark 0.2.0</li> <li>bigdecimal 3.1.1</li> <li>bundler 2.3.3</li> <li>cgi 0.3.1</li> <li>csv 3.2.2</li> <li>date 3.2.2</li> <li>did_you_mean 1.6.1</li> <li>digest 3.1.0</li> <li>drb 2.1.0</li> <li>erb 2.2.3</li> <li>error_highlight 0.3.0</li> <li>etc 1.3.0</li> <li>fcntl 1.0.1</li> <li>fiddle 1.1.0</li> <li>fileutils 1.6.0</li> <li>find 0.1.1</li> <li>io-console 0.5.10</li> <li>io-wait 0.2.1</li> <li>ipaddr 1.2.3</li> <li>irb 1.4.1</li> <li>json 2.6.1</li> <li>logger 1.5.0</li> <li>net-http 0.2.0</li> <li>net-protocol 0.1.2</li> <li>nkf 0.1.1</li> <li>open-uri 0.2.0</li> <li>openssl 3.0.0</li> <li>optparse 0.2.0</li> <li>ostruct 0.5.2</li> <li>pathname 0.2.0</li> <li>pp 0.3.0</li> <li>prettyprint 0.1.1</li> <li>psych 4.0.3</li> <li>racc 1.6.0</li> <li>rdoc 6.4.0</li> <li>readline 0.0.3</li> <li>readline-ext 0.1.4</li> <li>reline 0.3.0</li> <li>resolv 0.2.1</li> <li>rinda 0.1.1</li> <li>ruby2_keywords 0.0.5</li> <li>securerandom 0.1.1</li> <li>set 1.0.2</li> <li>stringio 3.0.1</li> <li>strscan 3.0.1</li> <li>tempfile 0.1.2</li> <li>time 0.2.0</li> <li>timeout 0.2.0</li> <li>tmpdir 0.1.2</li> <li>un 0.2.0</li> <li>uri 0.11.0</li> <li>yaml 0.2.0</li> <li>zlib 2.1.1</li> </ul> </li> <li>The following bundled gems are updated. <ul> <li>minitest 5.15.0</li> <li>power_assert 2.0.1</li> <li>rake 13.0.6</li> <li>test-unit 3.5.3</li> <li>rexml 3.2.5</li> <li>rbs 2.0.0</li> <li>typeprof 0.21.1</li> </ul> </li> <li>The following default gems are now bundled gems. You need to add the following libraries to <code class="language-plaintext highlighter-rouge">Gemfile</code> under the bundler environment. <ul> <li>net-ftp 0.1.3</li> <li>net-imap 0.2.2</li> <li>net-pop 0.1.1</li> <li>net-smtp 0.3.1</li> <li>matrix 0.4.2</li> <li>prime 0.1.2</li> <li>debug 1.4.0</li> </ul> </li> </ul> <p>See <a href="https://github.com/ruby/ruby/blob/v3_1_0/NEWS.md">NEWS</a> or the <a href="https://github.com/ruby/ruby/compare/v3_0_0...v3_1_0">commit logs</a> for more details.</p> <p>With those changes, <a href="https://github.com/ruby/ruby/compare/v3_0_0...v3_1_0#file_bucket">3124 files changed, 551760 insertions(+), 99167 deletions(-)</a> since Ruby 3.0.0!</p> <p>Merry Christmas, Happy Holidays, and enjoy programming with Ruby 3.1!</p> <h2>Download</h2> <ul> <li> <p><a href="https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.gz">https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.gz</a></p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>SIZE: 20103517 SHA1: e4e8c20dd2a1fdef4d3e5bd5a3461000dd17f226 SHA256: 50a0504c6edcb4d61ce6b8cfdbddaa95707195fab0ecd7b5e92654b2a9412854 SHA512: 76009d325e961e601d9a287e36490cbc1f3b5dbf4878fa6eab2c4daa5ff2fed78cbc7525cd87b09828f97cbe2beb30f528928bcc5647af745d03dffe7c5baaa9 </code></pre></div> </div> </li> <li> <p><a href="https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.xz">https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.xz</a></p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>SIZE: 14709096 SHA1: 92b603c2a69fb25d66c337a63e94280984edea11 SHA256: 1a0e0b69b9b062b6299ff1f6c6d77b66aff3995f63d1d8b8771e7a113ec472e2 SHA512: a2bb6b5e62d5fa06dd9c30cf84ddcb2c27cb87fbaaffd2309a44391a6b110e1dde6b7b0d8c659b56387ee3c9b4264003f3532d5a374123a7c187ebba9293f320 </code></pre></div> </div> </li> <li> <p><a href="https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.zip">https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.zip</a></p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>SIZE: 24388179 SHA1: e37435956d6f840a0e8758d7374bc7e0e346105f SHA256: a3bfcd486d09c065d46421da0ff3d430ce4423fefd80cea63c6595d83ae4af0e SHA512: 67db71144e06da2c1c25eaf413d1417c99a4b18738a573f9e3371c11ea242eee9dcbdc3de17336f25ab5060039fe034e57298943d344be9cd9eb33bb56e2e1c6 </code></pre></div> </div> </li> </ul> <h2>What is Ruby</h2> <p>Ruby was first developed by Matz (Yukihiro Matsumoto) in 1993, and is now developed as Open Source. It runs on multiple platforms and is used all over the world especially for web development.</p> </div> </div> <hr class="hidden-modern" /> <div id="sidebar-wrapper"> <div id="sidebar"> <div class="navigation"> <h3><strong>Recent News</strong></h3> <ul class="menu"> <li><a href="/en/news/2025/02/14/ruby-3-4-2-released/">Ruby 3.4.2 Released</a></li> <li><a href="/en/news/2025/02/10/dos-net-imap-cve-2025-25186/">CVE-2025-25186: DoS vulnerability in net-imap</a></li> <li><a href="/en/news/2025/02/04/ruby-3-2-7-released/">Ruby 3.2.7 Released</a></li> <li><a href="/en/news/2025/01/15/ruby-3-3-7-released/">Ruby 3.3.7 Released</a></li> <li><a href="/en/news/2024/12/25/ruby-3-4-1-released/">Ruby 3.4.1 Released</a></li> </ul> </div> <h3>Syndicate</h3> <p><a href="/en/feeds/news.rss">Recent News (RSS)</a></p> </div> </div> <hr class="hidden-modern" /> </div> </div> </div> <div class="container"> <div id="footer"> <div class="site-links"> <a href="/en/" class="home">Home</a> <a href="/en/downloads/">Downloads</a> <a href="/en/documentation/">Documentation</a> <a href="/en/libraries/">Libraries</a> <a href="/en/community/">Community</a> <a href="/en/news/">News</a> <a href="/en/security/">Security</a> <a href="/en/about/">About Ruby</a> </div> <p> This site in other languages: <a href="/bg/">Български</a>, <a href="/de/">Deutsch</a>, <a href="/en/">English</a>, <a href="/es/">Español</a>, <a href="/fr/">Français</a>, <a href="/id/">Bahasa Indonesia</a>, <a href="/it/">Italiano</a>, <a href="/ja/">日本語</a>, <a href="/ko/">한국어</a>, <a href="/pl/">polski</a>, <a href="/pt/">Português</a>, <a href="/ru/">Русский</a>, <a href="/tr/">Türkçe</a>, <a href="/vi/">Tiếng Việt</a>, <a href="/zh_cn/">简体中文</a>, <a href="/zh_tw/">繁體中文</a>. </p> <p><a href="/en/about/website/">This website</a> is proudly maintained by members of the Ruby community.</p> </div> </div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10