Ruby Next Versions Save

Ruby Next makes modern Ruby code run in older versions and alternative implementations

v1.0.0

5 months ago

We glad to announce first major release! It indicates both stability we achieved over the years and the initial roadmap completion.

Highlights

  • Text rewriters.

    We made experimenting with Ruby syntax as simple as possible by introducing text rewriters. No need to manipulate ASTs or write your own parser. Text rewriters allow you manipulate Ruby code the way you prefer (regexps, strings scanners, etc.). You can also use our new parse combinator library, Paco, to have more control over transformations. Read more in the documentation.

  • Robust runtime transpiling with require-hooks.

    We extracted functionality to hijack Ruby's require/load mechanism into a standalone gem, require-hooks. It passes most of the Ruby Spec and provides a universal interface to interfere with code loading for major Ruby implementations.

Features

  • New rewriters:
    • Added it block parameter support from Ruby 3.4 (proc { it }.call("ruby-next") == "ruby-next").
    • Added anonymous rest and keyword rest arguments forwarding support (def foo(*, **); bar(*, **) end).
  • Core APIs:
    • Added Data backport.
    • Added MatchData#deconstruct, MatchData#deconstruct_keys, Time#deconstruct_keys

Read more in our changelog.

P.S. Happy holidays 🎄

v0.15.0

2 years ago

Features

  • IRB and Pry support added.

Now you can run modern Ruby code in your REPL.

  • Added support for rescue/ensure/else within blocks (for Ruby < 2.5).

v0.14.0

2 years ago

This release brings Ruby 3.1 features and more.

New syntax

  • (Proposed) Binding instance, class, global variables in pattern matching (42 => @v) (#18408).

This brings back rightward assignment: 42 => @v.

  • Shorthand Hash/kwarg notation (data = {x:, y:} or foo(x:, y:)) (#15236).

  • Pinning instance, class and global variables and expressions (#17724, #17411).

  • Anonymous blocks def b(&); c(&); end (#11256).

  • Command syntax in endless methods (def foo() = puts "bar") (#17398)

  • Support omitting parentheses in one-line pattern matching ({a: 1} in a:)

New APIs

  • Refinement#import_methods (#17429)

(There are some limitations though).

  • MatchData#match (#18172)

  • Enumerable#compact, Enumerator::Lazy#compact (#17312)

  • Integer.try_convert (#15211)

v0.12.0

3 years ago

Features

  • Added partial Ruby 2.0 support.

Where "partial" means that you can generate Ruby 2.0 compatible source code via Ruby Next, but Ruby Next itself still requires Ruby 2.2+.

Fixes

  • [#68] Avoid double evaluation of safe navigation target.

v0.11.0

3 years ago

This release is dedicated to the upcoming release of Ruby 3.0.

Features

  • Added find pattern support (case v; in [*, 42, *]; true; end)
  • Added endless method support (def foo() = "bar")
  • Added leading arguments support to arguments forwarding (def foo(...) = bar(1, ...)).

Changes

  • Right-hand assignment replaced with single-line pattern matching (a => x)
  • Behavior of a in x single-line pattern matching changed to comply with Ruby 3.0 (returns true/false instead of raising errors).
  • Transpiler now uses rewrite mode by default.

Bonus features

we also extended the proposed shorthand Hash syntax to support kwargs in method calls as well:

x = 1
y = 2

foo x:, y: #= foo x: x, y: y

Could this be the future Ruby? Share your thoughts!.

v0.10.0

3 years ago

RubyKaigi 2020 special.

🔬 Experimental

  • Added proposed shorthand Hash syntax.

From https://bugs.ruby-lang.org/issues/15236.

Give it a try: x = 1; y = 2; data = {x, y}.

Here is a real-life example usage: https://github.com/anycable/anycable_rails_demo/commit/d4ee4c614083d633edd9fb2601f1764860ff6f34

Ruby 3.0

  • Added find pattern support to pattern matching.

Example: [0, 1, 2] in [*, 1 => a, *c].

  • Added leading argument support to args forwarding.

Example: def a(...) b(1, ...); end.

  • Added Hash#except.

Example: {a: 1, b: 2}.except(:a) == {b: 2}

Misc

  • Added Ruby 2.2 support.

With support for safe navigation operator (&.) and squiggly heredocs (<<~TXT).

v0.8.0

4 years ago

This release begins adding support for Ruby 2.8 (to be 3.0) features.

Features

  • Add right-hand assignment support.

It is real: 13.divmod(5) => a, b.

  • Add endless methods support.

Now you can write def foo() = :bar.

v0.6.0

4 years ago

Changes

  • Ruby Next parser no longer need to installed from a custom package registry.

Now we use ruby-next-parser gem which adds the next parser capabilities to the official Parser gem.

  • Changed the way edge/proposed features are activated.

Use --edge or --proposed flags for ruby-next nextify or require "ruby-next/language/{edge,proposed}" in your code.

See more in the Readme.

  • Updated RuboCop integration.

Make sure you use TargetRubyVersion: next in your RuboCop configuration. That's a preliminary step to make unreleased Ruby features work with RuboCop.

v0.5.0

4 years ago

Added rewrite transpiler mode.

Add support for rewriting the source code instead of rebuilding it from scratch to preserve the original layout and improve the debugging experience.

Currently, disable by default. Opt-in via: -RUBY_NEXT_TRANSPILE_MODE=rewrite

  • RubyNext::Language.mode = :rewrite
  • ruby-next nextify --transpile-mode=rewrite.

v0.4.0

4 years ago

Changes

  • Optimized pattern matching code.

For array patterns, transpiled code is ~1.5-2x faster than native. For hash patterns it's about the same.

  • Pattern matching is 100% compatible with RubySpec.

Features

  • Add Symbol#start_with?/end_with?.