README.md in ruby-next-0.8.0 vs README.md in ruby-next-0.9.0.pre

- old
+ new

@@ -15,17 +15,33 @@ - **Users of non-MRI implementations** such as [mruby][], [JRuby][], [TruffleRuby][], [Opal][], [RubyMotion][], [Artichoke][], [Prism][]. Ruby Next also aims to help the community to assess new, _experimental_, MRI features by making it easier to play with them. That's why Ruby Next implements the `master` features as fast as possible. +Read more about the motivation behind the Ruby Next in this post: [Ruby Next: Make all Rubies quack alike](https://evilmartians.com/chronicles/ruby-next-make-all-rubies-quack-alike). + <a href="https://evilmartians.com/?utm_source=ruby-next"> <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a> -## Links +## Posts +- [Ruby Next: Make all Rubies quack alike](https://evilmartians.com/chronicles/ruby-next-make-all-rubies-quack-alike) + +## Talks + - [Ruby Next: Make old Rubies quack like a new one](https://noti.st/palkan/j3i2Dr/ruby-next-make-old-rubies-quack-like-a-new-one) (RubyConf 2019) +## Examples + +- Ruby gems + - [anyway_config](https://github.com/palkan/anyway_config) + - [graphql-fragment_cache](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache) +- mruby + - [ACLI](https://github.com/palkan/acli) + +_Please, submit a PR to add your project to the list!_ + ## Table of contents - [Overview](#overview) - [Quick Start](#quick-start) - [Polyfills](#using-only-polyfills) @@ -36,10 +52,11 @@ - [Runtime usage](#runtime-usage) - [Bootsnap integration](#using-with-bootsnap) - [`ruby -ruby-next`](#uby-next) - [Logging & Debugging](#logging-and-debugging) - [RuboCop](#rubocop) +- [Using with EOL Rubies](#using-with-eol-rubies) - [Proposed & edge features](#proposed-and-edge-features) ## Overview Ruby Next consists of two parts: **core** and **language**. @@ -47,13 +64,14 @@ Core provides **polyfills** for Ruby core classes APIs via Refinements (default strategy) or core extensions (optionally or for refinement-less environments). Language is responsible for **transpiling** edge Ruby syntax into older versions. It could be done programmatically or via CLI. It also could be done in runtime. -Currently, Ruby Next supports Ruby versions 2.5+ (including JRuby 9.2.8+). -Please, [open an issue](https://github.com/ruby-next/ruby-next/issues/new/choose) if you would like us to support older Ruby versions. +Currently, Ruby Next supports Ruby versions 2.4+ (including JRuby 9.2.8+). Support for EOL versions (<2.5) slightly differs though ([see below](#using-with-eol-rubies)). +Please, [open an issue](https://github.com/ruby-next/ruby-next/issues/new/choose) or join the discussion in the existing ones if you would like us to support older Ruby versions. + ## Quick start The quickest way to start experimenting with Ruby Next is to install the gem and run a sample script. For example: ```sh @@ -295,21 +313,21 @@ If you're using [runtime mode](#runtime-usage) a long with `setup_gem_load_path` (e.g., in tests), the transpiled files are ignored (i.e., we do not modify `$LOAD_PATH`). \* Ruby Next avoids storing duplicates; instead, only the code for the earlier version is created and is assumed to be used with other versions. For example, if the transpiled code is the same for Ruby 2.5 and Ruby 2.6, only the `.rbnext/2.7/path/to/file.rb` is kept. That's why multiple entries are added to the `$LOAD_PATH` (`.rbnext/2.6` and `.rbnext/2.7` in the specified order for Ruby 2.5 and only `.rbnext/2.7` for Ruby 2.6). -### Transpiled files vs. VSC vs. installing from source +### Transpiled files vs. VCS vs. installing from source It's a best practice to not keep generated files in repositories. In case of Ruby Next, it's a `lib/.rbnext` folder. -We recommend adding this folder only to the gem package (i.e., it should be added to your `spec.files`) and ignore it in your VSC (e.g., `echo ".rbnext/" >> .gitignore`). That would make transpiled files available in releases without polluting your repository. +We recommend adding this folder only to the gem package (i.e., it should be added to your `spec.files`) and ignore it in your VCS (e.g., `echo ".rbnext/" >> .gitignore`). That would make transpiled files available in releases without polluting your repository. -What if someone decides to install your gem from the VSC source? They would likely face some syntax errors due to the missing transpiled files. +What if someone decides to install your gem from the VCS source? They would likely face some syntax errors due to the missing transpiled files. To solve this problem, Ruby Next _tries_ to transpile the source code when you call `#setup_gem_load_path`. It does this by calling `bundle exec ruby-next nextify <lib_dir> -o <next_dir>`. We make the following assumptions: -- We in the Bundler context (since that's the most common way of installing gems from source). +- We are in the Bundler context (since that's the most common way of installing gems from source). - Our Gemfile contains `ruby-next` gem. - We use [`.rbnextrc`](#CLI-configuration-file) for transpiling options. If the command fails we warn the end user. @@ -404,10 +422,44 @@ - 'lib/.rbnext/**/*' ``` **NOTE:** you need `ruby-next` gem available in the environment where you run RuboCop (having `ruby-next-core` is not enough). +## Using with EOL Rubies + +**NOTE:** Use Ruby Next `0.9.0.pre` to use this feature. + +We currently provide experimental support for Ruby 2.4. Work on older Rubies (down to 2.2) is in progress. + +Ruby Next itself relies on 2.5 features and contains polyfills only for version 2.5+ (and that won't change). +Thus, to make it work with <2.5 we need to backport some APIs ourselves. + +The recommended way of doing this is to use [backports][] gem. You need to load backports **before Ruby Next**. + +When using runtime features, you should do the following: + +```ruby +# first, require backports upto 2.5 +require "backports/2.5" +# then, load Ruby Next +require "ruby-next" +# if you need 2.6+ APIs, add Ruby Next core_ext +require "ruby-next/core_ext" +# then, load runtime transpiling +require "ruby-next/language/runtime" +# or +require "ruby-next/language/bootsnap" +``` + +To load backports while using `ruby-next nextify` command, you must configure the environment variable: + +```sh +RUBY_NEXT_CORE_STRATEGY=backports ruby-next nextify lib/ +``` + +**NOTE:** Make sure you have `backports` gem installed globally or added to your bundle (if you're using `bundle exec ruby-next ...`). + ## Proposed and edge features Ruby Next aims to bring edge and proposed features to Ruby community before they (hopefully) reach an official Ruby release. This includes: @@ -468,5 +520,6 @@ [parser]: https://github.com/whitequark/parser [unparser]: https://github.com/mbj/unparser [next_parser]: https://github.com/ruby-next/parser [Bootsnap]: https://github.com/Shopify/bootsnap [rubocop]: https://github.com/rubocop-hq/rubocop +[backports]: https://github.com/marcandre/backports