README.md in ruby-next-0.2.0 vs README.md in ruby-next-0.3.0
- old
+ new
@@ -24,12 +24,11 @@
## Overview
Ruby Next consists of two parts: **core** and **language**.
-Core provides **polyfills** for Ruby core classes APIs via Refinements.
-Thus, polyfills are only available in compatible runtimes (MRI, JRuby, TruffleRuby).
+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+).
@@ -61,10 +60,24 @@
using RubyNext
```
Ruby Next only refines core classes if necessary; thus, this line wouldn't have any effect in the edge Ruby.
+**NOTE:** Even if the runtime already contains a monkey-patch with the backported functionality, we consider the method as _dirty_ and activate the refinement for it. Thus, you always have a predictable behaviour. That's why we recommend using refinements for gems development.
+
+Alternatively, you can go with monkey-patches. Just add this line:
+
+```ruby
+require "ruby-next/core_ext"
+```
+
+The following _rule of thumb_ is recommended when choosing between refinements and monkey-patches:
+
+- Use refinements for libraries development (to avoid conflicts with others code)
+- Using core extensions could be considered for application development (no need to think about `using RubyNext`); this approach could potentially lead to conflicts with dependendices (if these dependencies are not using refinements 🙂)
+- Use core extensions if refinements are not supported by your platform
+
[**The list of supported APIs.**][features_core]
## Transpiling, or using edge Ruby syntax features
Ruby Next transpiler relies on two libraries: [parser][] and [unparser][].
@@ -123,31 +136,80 @@
## CLI
Ruby Next ships with the command-line interface (`ruby-next`) which provides the following functionality:
-- `ruby-next nextify` — transpile file or directory into older Rubies (see, for example, the "Integrating into a gem development" section above).
+### `ruby-next nextify`
+This command allows you to transpile a file or directory into older Rubies (see, for example, the "Integrating into a gem development" section above).
+
It has the following interface:
```sh
$ ruby-next nextify
Usage: ruby-next nextify DIRECTORY_OR_FILE [options]
- -o, --output=OUTPUT Specify output directory or file
- --min-version=VERSION Specify the minimum Ruby version to support
- --single-version Only create one version of a file (for the earliest Ruby version)
- -V Turn on verbose mode
+ -o, --output=OUTPUT Specify output directory or file or stdout (use -o stdout for that)
+ --min-version=VERSION Specify the minimum Ruby version to support
+ --single-version Only create one version of a file (for the earliest Ruby version)
+ --enable-method-reference Enable reverted method reference syntax (requires custom parser)
+ --[no-]refine Do not inject `using RubyNext`
+ -h, --help Print help
+ -V Turn on verbose mode
```
The behaviour depends on whether you transpile a single file or a directory:
- When transpiling a directory, the `.rbnext` subfolder is created within the target folder with subfolders for each supported Ruby versions (e.g., `.rbnext/2.6`, `.rbnext/2.7`). If you want to create only a single version (the smallest), you can also pass `--single-version` flag. In that case, no version directory is created (i.e., transpiled files go into `.rbnext`).
- When transpiling a file and providing the output path as a _file_ path, only a single version is created. For example:
```sh
$ ruby-next nextify my_ruby.rb -o my_ruby_next.rb -V
+RubyNext core strategy: refine
Generated: my_ruby_next.rb
+```
+
+### `ruby-next core_ext`
+
+This command could be used to generate a Ruby file with a configurable set of core extensions.
+
+Use this command if you want to backport new Ruby features to Ruby implementations not compatible with RubyGems.
+
+It has the following interface:
+
+```sh
+$ ruby-next core_ext
+Usage: ruby-next core_ext [options]
+ -o, --output=OUTPUT Specify output file or stdout (default: ./core_ext.rb)
+ -l, --list List all available extensions
+ --min-version=VERSION Specify the minimum Ruby version to support
+ -n, --name=NAME Filter extensions by name
+ -h, --help Print help
+ -V Turn on verbose mode
+```
+
+The most common usecase is to backport the APIs required by pattern matching. You can do this, for example,
+by including only monkey-patches containing the `"deconstruct"` in their names:
+
+```sh
+ruby-next core_ext -n deconstruct -o pattern_matching_core_ext.rb
+```
+
+To list all available (are matching if `--min-version` or `--name` specified) monkey-patches, use the `-l` switch:
+
+```sh
+$ ruby-next core_ext -l --name=filter --name=deconstruct
+2.6 extensions:
+ - ArrayFilter
+ - EnumerableFilter
+ - HashFilter
+
+2.7 extensions:
+ - ArrayDeconstruct
+ - EnumerableFilterMap
+ - EnumeratorLazyFilterMap
+ - HashDeconstructKeys
+ - StructDeconstruct
```
## Runtime mode
It is also possible to transpile Ruby source code in run-time via Ruby Next.