Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
The latest features of Ruby backported to older versions.
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.document
.gitignore
CHANGELOG.rdoc
LICENSE
README.rdoc
Rakefile
VERSION.yml
backports.gemspec

README.rdoc

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 rails or ruby

  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 activesupport (even things like String::pluralize), won't be included. require 'activesupport' if you need them!

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

Compatibility

Works with ruby 1.8 & 1.9

List of backports

  • Symbol

    • to_proc (e.g. foo.map(&:bar) )

  • Kernel

    • require_relative

  • Module

    • alias_method_chain

  • Object

    • tap, returning

    • try

  • String

    • start_with?, end_with?

    • camelize, underscore

    • dasherize, demodulize

    • constantize

  • Hash

    • Hash[[[:foo, :bar],[:hello, "world"]]] ==> {:foo => :bar, :hello => "world"}

    • 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

  • Array

    • flatten, flatten!

    • find_index, find

    • reverse_each

    • cycle

  • Fixnum

    • odd?, even?

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

License

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.

Author

Marc-André Lafortune

Something went wrong with that request. Please try again.