public
Description: Run Ruby 1.8.7 on older Ruby 1.8.x versions. Enables some of the really nice features of ruby 1.9 and rails too.
Homepage:
Clone URL: git://github.com/marcandre/backports.git
name age message
file .document Wed Apr 01 09:00:50 -0700 2009 Initial commit to backports. [marcandre]
file .gitignore Wed May 27 15:23:11 -0700 2009 Stronger argument checking, cleanup Also added... [marcandre]
file CHANGELOG.rdoc Sat Oct 03 09:49:32 -0700 2009 Fix issues 8 & 9 (thanks Roger Pack) [marcandre]
file LICENSE Wed Apr 01 09:00:50 -0700 2009 Initial commit to backports. [marcandre]
file README.rdoc Mon Sep 28 21:25:45 -0700 2009 Added info on smtp_tls [marcandre]
file Rakefile Mon Aug 31 12:17:17 -0700 2009 v1.8.0: Backports can be required selectively: ... [marcandre]
file VERSION.yml Tue Oct 27 23:13:36 -0700 2009 Version bump to 1.10.3 [marcandre]
file backports.gemspec Tue Oct 27 23:13:46 -0700 2009 Regenerated gemspec for version 1.10.3 [marcandre]
directory lib/ Loading commit data...
directory test/ Fri Oct 02 23:17:16 -0700 2009 Enumerable#chunk: fix small bugs to pass rubyspec [marcandre]
README.rdoc

Backports Library

Would you like to use features of Ruby 1.8.7 without the need of having 1.8.7 installed? Simply

  require 'backports/1.8.7'

All 1.8.7 features are now available! Some of the features of 1.9 are also available with

  require 'backports/1.9'

Finally, some features of rails’ active-support are also available with

  require 'backports/rails'

If you want them all:

  require 'backports'

What’s inside

All features of 1.8.7 are backported (well, almost all, see the exception list bellow).

Conditions for inclusion of ruby 1.9 and activesupport features:

  1. Won’t break older code
  2. Simple and self-contained

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. Such incompatibilities between 1.8 and 1.9 methods are left unchanged.

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!

Installation & compatibility

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

  sudo gem install backports

To use:

  require 'rubygems'
  require 'backports'   # or a subset like "backports/1.8.7"
  # and off you go!

Compatible with Ruby 1.8 & 1.9, jruby and rubinius.

Complete List of backports

Ruby 1.8.7

Complete Ruby 1.8.7 backporting (core language). Refer to the official list of changes.

Only exceptions:

  • String#gsub
  • GC.stress=
  • Array#choice (use Array#sample instead)
  • recursive data handling (Array, Hash, …)

Libraries have not been backported. See at the end for list of known library backports

Ruby 1.9

Additionally, the following Ruby 1.9 have been backported:

  • Array
    • try_convert
  • Enumerable
    • each_with_object
    • chunk
  • Enumerator
    • new (with block)
  • File
    • binread
    • to_path
    • All class methods accepting filenames will accept files or anything with a #to_path method.
  • Hash
    • try_convert
    • default_proc=
  • Kernel
    • require_relative
  • Object
    • define_singleton_method
    • +respond_to_missing?+
  • Proc
    • yield
  • String
    • try_convert
    • ascii_only?
    • chr
    • clear
    • codepoints, each_codepoint

Enumerator can be accessed directly (instead of Enumerable::Enumerator)

Moreover, a pretty good imitation of BasicObject is available, but it must be required explicitely:

  require 'backports/basic_object'

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

Libraries

Libraries have not been backported. I am aware of following the backport gems:

  • Net::SMTP for Ruby 1.8.6: smtp_tls
  • Let me know of others…

License

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

Author:Marc-André Lafortune