Skip to content

Latest commit

 

History

History
125 lines (88 loc) · 2.86 KB

README.rdoc

File metadata and controls

125 lines (88 loc) · 2.86 KB

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

Ruby 1.8.7

Complete Ruby 1.8.7 backporting. Refer to the official list of changes. All builtin classes are compatible with Ruby 1.8.7:

  • Array

  • Binding

  • Dir

  • Enumerable

  • Enumerator

  • Fixnum

  • Hash

  • Integer

  • IO (& ARGF)

  • Method

  • Numeric

  • Object

  • ObjectSpace

  • Range

  • Regexp

  • Symbol

  • UnboundMethod

Only exceptions:

  • String#gsub

  • GC.stress=

  • Process.exec

  • recursive data handling (Array and Hash)

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

Ruby 1.9

Additionally, the following Ruby 1.9 have been backported:

  • Array

    • sample

  • Enumerable

    • each_with_object

    • reverse_each

  • Enumerator

    • new (with block)

  • Hash

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

    • default_proc=

  • Kernel

    • require_relative

  • Object

    • define_singleton_method

  • Proc

    • yield

  • String

    • try_convert

    • ascii_only?

    • chr

    • clear

    • codepoints, each_codepoint

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

Rails

Some generic methods from Rails methods have been copied:

  • Enumerable

    • sum

  • Hash

    • symbolize_keys, symbolize_keys!

    • reverse_merge, reverse_merge!

  • Module

    • alias_method_chain

  • Object

    • try

    • returning

  • String

    • camelize, underscore

    • dasherize, demodulize

    • constantize

License

backports is released under the terms of the MIT License, see the included LICENSE file.

Author

Marc-André Lafortune