Skip to content


Subversion checkout URL

You can clone with
Download ZIP
The latest features of Ruby backported to older versions.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Backports Library

Essential backports that make it possible to use some of the really nice features of Ruby 1.8.7, Ruby 1.9 and rails from Ruby 1.8.x

Conditions for inclusion:

  1. Standard in either Ruby or Rails

  2. Won't break older code

  3. Simple and self-contained

The first and second rules avoids conflicts in future and the past respectively. Because of the second rule, incompatibilities between 1.8 and 1.9 methods are left alone. For example, Module::instance_methods returns strings in 1.8 and symbols in 1.9; no change can be made without the risk of breaking existing code.

More complex features of active-support (even things like String::pluralize), won't be included. require 'activesupport' if you need them and are not in rails!

I've added these backports as I need them; pull requests welcome (with tests for Ruby 1.9 backports)

Installation & compatibility

backports is mirrored on Rubyforge and can thus be installed with:

sudo gem install backports

To use:

require 'rubygems'
require 'backports'
# and off you go!

Compatible with Ruby 1.8 & 1.9.

List of backports

  • Symbol

    • to_proc (e.g. )

  • Kernel

    • require_relative

  • Module

    • alias_method_chain

  • Object

    • tap, returning

    • try

  • String

    • each_char, chars

    • start_with?, end_with?

    • camelize, underscore

    • dasherize, demodulize

    • constantize

    • partition, rpartition

  • Hash

    • Hash[[[:foo, :bar],[:hello, "world"]]] ==> {:foo => :bar, :hello => "world"} (see note)

    • key

    • symbolize_keys, symbolize_keys!

    • reverse_merge, reverse_merge!

    • default_proc=

  • Enumerable

    • sum

    • find_index

    • take, take_while, drop, drop_while

    • first

    • reverse_each

    • count

    • cycle

    • group_by

    • none?

  • Array

    • flatten, flatten!

    • find_index, find

    • reverse_each

    • cycle

  • Fixnum

    • odd?, even?

  • Prox

    • yield

Finally, there is no need to require 'enumerator' in older Ruby, and Enumerator can be accessed directly (instead of Enumerable::Enumerator)

note: This usage of Hash::[] is not yet documented.


backports is released under the terms of the MIT License, see the included LICENSE file. The code for backports was copied from rails when available.


Marc-André Lafortune

Something went wrong with that request. Please try again.