Path: | README.rdoc |
Last Update: | Tue May 22 01:04:37 +0000 2012 |
This gem is for you!
The goal of ‘backports’ is to make it easier to write ruby code that runs across different versions of Ruby. All you need to bring any version of Ruby up to today‘s standards:
require 'backports'
This will bring in all the features of 1.8.7 (for Ruby 1.8.6) and many features of Ruby 1.9.1 (for Ruby 1.8.x), Ruby 1.9.2 and Ruby 1.9.3 (for all earlier versions)!
Note: Although I am a Ruby committer, this gem is a personal project and is not endorsed by ruby-core.
Features in this gem:
Let‘s be a bit more precise about the breaking code business. It is of course entirely possible that code will break, for example some core methods are monkeypatched or if the code relies on a certain call raising an exception. Example: [42].sample rescue "dum example" will return "dum example" without this gem and 42 with it.
A real incompatibility is, for example, Module::instance_methods which returns strings in 1.8 and symbols in 1.9. No change can be made without the risk of breaking existing code. Such incompatibilities are left unchanged, although you can require some of these changes in addition (see below)
All features of 1.8.7 are backported (well, almost all, see the exception list bellow), and many of 1.9 are also.
Some generic and self-contained features of active-support are also included. By simple I mean that String#camelcase is there, but pluralize isn‘t.
backports is can be installed with:
(sudo) gem install backports
To use:
require 'rubygems' require 'backports' # or a subset, see next section
Compatible with Ruby 1.8.6, 1.8.7, 1.9.1, 1.9.2, 1.9.3, JRuby and Rubinius.
Complete Ruby 1.8.7 backporting (core language). Refer to the official list of changes.
Only exceptions:
To include only these backports, require "backports/1.8.7"
Ruby 1.8.8 has been officially cancelled. As of version 2.2, require "backports/1.8.8" does nothing.
Additionally, the following Ruby 1.9 features have been backported:
Enumerator can be accessed directly (instead of Enumerable::Enumerator)
To include only these backports and those of the 1.8 line, require "backports/1.9.1".
Moreover, a pretty good imitation of BasicObject is available, but since it is only an imitation, it must be required explicitly:
require 'backports/basic_object'
Finally, most of Ruby 1.9.2 features have been backported:
To include all Ruby backports but not those of Rails, require "backports/1.9.2" (or "backports/1.9")
Some features of Ruby 1.9.3 have been backported:
Some generic methods from Rails methods have been copied:
To include only these Rails backports but not those of Ruby, require "backports/rails".
Libraries are slowly being backported. You simply require them as usual, ideally (but not necessarily) after requiring backports.
require "backports" require "prime" 42.prime? # => false, even in Ruby 1.8.x
The following libraries are up to date with Ruby 1.9.3:
I am aware of the following backport gem which will hopefully be part of backports soon:
Some backports would create incompatibilities in their current Ruby version but could be useful in some projects. It is possible to request such incompatible changes. Backports currently supports the following:
These must be imported in addition to the backports gem, for example:
require "backports" require "backports/force/hash_select" {}.select{} # => {}, even in Ruby 1.8
Thanks for the bug reports and patches, in particular the repeat offenders:
The best way to submit a patch is to also submit a patch to RubySpec and then a patch to backports that make it pass the spec. To test rubyspec along with backports, one way to test this is:
mspec path/to/specs -t path/to/ruby186 --unguarded -r path/to/backports
You must then check manually for which failures are acceptable and which are not.
backports is released under the terms of the MIT License, see the included LICENSE file.
Author: | Marc-André Lafortune |