https://github.com/marcandre/backports
The latest features of Ruby backported to older versions.
https://github.com/marcandre/backports
Keywords from Contributors
activerecord activejob mvc rspec rubygems rubocop rack sinatra crash-reporting static-code-analysis
Last synced: about 7 hours ago
JSON representation
Repository metadata
The latest features of Ruby backported to older versions.
- Host: GitHub
- URL: https://github.com/marcandre/backports
- Owner: marcandre
- License: mit
- Created: 2009-04-01T18:58:29.000Z (almost 17 years ago)
- Default Branch: master
- Last Pushed: 2025-12-15T19:46:31.000Z (22 days ago)
- Last Synced: 2025-12-16T11:02:50.197Z (22 days ago)
- Language: Ruby
- Homepage:
- Size: 1.09 MB
- Stars: 442
- Watchers: 10
- Forks: 53
- Open Issues: 6
- Releases: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Security: SECURITY.md
README.md
Backports Library 
Yearning to write a gem using some new cool features in Ruby 3.3 while
still supporting Ruby 2.5.x?
Have some legacy code in Ruby 1.8 but can't live without flat_map?
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.
Loading backports
Explicitly (recommended)
For example, if you want to use transform_values and transform_keys, even in
Ruby implementations that don't include it:
require 'backports/2.4.0/hash/transform_values'
require 'backports/2.5.0/hash/transform_keys'
This will enable Hash#transform_values and Hash#transform_keys, using the
native versions if available or otherwise provide a pure Ruby version.
By Module
To bring all the backports for a given Class/Module, you can specify only that
Class:
require 'backports/2.3.0/hash'
This will make sure that Hash responds to dig, fetch_values, to_proc and comparisons.
Up to a specific Ruby version (for quick coding)
You can load all backports up to a specific version.
For example, to bring any version of Ruby mostly up to Ruby 3.3.0's standards:
require 'backports/3.3.0'
This will bring in all the features of 1.8.7 and many features of Ruby 1.9.x
all the way up to Ruby 3.3.0 (for all versions of Ruby)!
You may require 'backports/latest' as a
shortcut to the latest Ruby version supported.
Note: For production / public gems, it is highly recommended you only require
the backports you need explicitly.
Note: Although I am a Ruby committer, this gem is a personal project and is
not endorsed by ruby-core.
What's inside
Goals for backported features:
- Won't break older code
- Pure Ruby (no C extensions)
- Pass ruby/spec
Let's be a bit more precise about the "breaking code" business. It is of
course entirely possible that code will break. In particular, you may be
distinguishing parameters with duck typing, but a builtin class may, in the
future, be responding to a particular call. Here's an example from Rails
that is relying on the fact that Proc and Method respond to :to_proc and Hash
isn't. That is, until Ruby 2.3... This old version of Rails therefore won't
work on Ruby 2.3, or on older Rubies with that the 2.3.0/hash/to_proc
loaded...
For Ruby < 2.0, there are some real incompatibilities. 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).
Installation & compatibility
backports can be installed with:
gem install backports
To use:
require 'rubygems'
# For only specific backports:
require 'backports/1.9.1/kernel/require_relative'
require 'backports/2.0.0/enumerable/lazy'
# For all backports up to a given version
require 'backports/1.9.2' # All backports for Ruby 1.9.2 and below
Note: about a dozen of backports have a dependency that will be also loaded.
For example, the backport of Enumerable#flat_map uses flatten(1), so if
required from Ruby 1.8.6 (where Array#flatten does not accept an argument),
the backport for Ruby's 1.8.7 flatten with an argument will also be loaded.
With bundler, add to your Gemfile:
gem 'backports', :require => false
Run bundle install and require the desired backports. Compatible with Ruby
itself, JRuby and Rubinius.
Complete List of backports
Ruby 3.3 backports
MatchData
named_captures(withsymbolize_keysoption)
Range
reverse_each(with correct handling of endless Ranges)overlap?
Ruby 3.2 backports
Class
attached_object
Data
- Complete class
Enumerator
Enumerator.productandEnumerator::Product
Hash
shift(with correct behavior when empty)
Integer
ceildiv
MatchData
byteoffset
Ruby 3.1 backports
Array
intersect?
Class
subclasses
Enumerable
compacttally(with hash argument)
File
dirname(with depth argument)
Integer
try_convert
MatchData
matchmatch_length
Struct
keyword_init?
Ruby 3.0 backports
Env
except
Hash
excepttransform_keys,transform_keys!(with hash argument)
Ractor
- All methods, with the caveats:
- uses Ruby's
Threadinternally - will not raise some errors when
Ractorwould (in particularRactor::IsolationError) - supported in Ruby 2.0+ only
- uses Ruby's
Symbol
name
Ruby 2.7 backports
Array
intersection
Comparable
clamp(with range)
Complex
<=>
Enumerable
filter_maptally
Enumerator
produce(class method)
Symbol
end_with?start_with?
Time
floor,ceil
Ruby 2.6 backports
Array
difference,unionto_h(with block)
Enumerable
chainto_h(with block)
Enumerator::Chain (use Enumerable#chain)
Hash
merge,merge!/update(with multiple arguments)to_h(with block)
Kernel
then
Method
<<,>>
Proc
<<,>>
Range
cover?(withRangeargument)
Ruby 2.5 backports
Array
append,prepend
Dir
children,each_child
Enumerable
any?,all?,none?,one?(with pattern argument)
Hash
slicetransform_keys
Integer
sqrtallbits?,anybits?andnobits?
Kernel
yield_self
Module
attr,attr_accessor,attr_reader,attr_writer(now public)define_method,alias_method,undef_method,remove_method(now
public)
String
delete_prefix,delete_prefix!delete_suffix,delete_suffix!undump
Struct
new(withkeyword_init: true)
Ruby 2.4 backports
Comparable
clamp
Enumerable
sumuniq
Hash
compact,compact!transform_values,transform_values!
Queue
close,closed?
Regexp
match?
String
match?unpack1
FalseClass, Fixnum, Bignum, Float, NilClass, TrueClass
dup
Ruby 2.3 backports
Array
bsearch_indexdig
Enumerable
chunk_whilegrep_v
Hash
digfetch_valuesto_proc- <=, <, >=, >
Numeric
negative?positive?
String
- unary + and -
Struct
dig
Ruby 2.2 backports
Enumerable
slice_afterslice_when
Float
prev_floatnext_float
Kernel
itself
Method
currysuper_method
String
unicode_normalizeunicode_normalize!unicode_normalize?
Ruby 2.1 backports
Array
to_h
Bignum
bit_length
Enumerable
to_h
Fixnum
bit_length
Module
include(now public)singleton_class?
Ruby 2.0 backports
Array
bsearch
Enumerable
lazy
Enumerator::Lazy
- all methods
Hash
default_proc=(with nil argument)to_h
nil.to_h
Range
bsearch
Struct
to_h
Ruby 1.9.3 backports
File
NULL
IO
advise(acts as a noop)write,binwrite
String
bytesliceprepend
Ruby 1.9.2 backports
Array
rotate, rotate!keep_if, select!product(with block)repeated_combination,repeated_permutationsort_by!uniq, uniq!(with block)
Complex
to_r
Dir
home
Enumerable
chunkflat_map,collect_concatjoinslice_before
Float::INFINITY, NAN
Hash
keep_if,select!
Object
singleton_class
Random (new class)
Note: The methods of Random can't be required individually; the class
can only be required whole with require 'backports/1.9.2/random'.
Ruby 1.9.1 backports
Additionally, the following Ruby 1.9 features have been backported:
Array
try_convertsample
Enumerable
each_with_objecteach_with_index(with arguments)
Enumerator
new(with block)
File
binreadto_path- All class methods accepting filenames will accept files or anything
with a#to_pathmethod. File.openaccepts an options hash.
Float
round
Hash
assoc,rassockeytry_convertdefault_proc=
Integer
magnituderound
IO
bin_readtry_convertungetbyteIO.openaccepts an options hash.
Kernel
require_relative
Math
log(with base)log2
Numeric
round
Object
define_singleton_methodpublic_methodpublic_send
Proc
yieldlambda?curry===
Range
cover?
Regexp
try_convert
String
ascii_only?chrclearcodepoints,each_codepointget_byte,set_byteordtry_convert
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'
Ruby 1.8.7
Complete Ruby 1.8.7 backporting (core language). Refer to the official list of
changes. That's about 130
backports!
Only exceptions:
String#gsub (the form returning an enumerator)
GC.stress= (not implemented)
Array#choice (removed in 1.9, use 1.9.1's Array#sample instead)
Libraries
Libraries were slowly being backported, but they are now available as separate gems.
The backports would be automatically used after requiring 'backports/std_lib' but this is now deprecated and discouraged.
The following libraries are up to date with Ruby 1.9.3:
Matrix
Prime
Set
The following library is to date with Ruby 2.0.0:
OpenStruct (ostruct)
I am aware of the following backport gem, which probably won't make it into
this gem:
Net::SMTP for Ruby 1.8.6:
[smtp_tls](http://seattlerb.rubyforge.org/smtp_tls/)
Requiring backports for a given version of Ruby will also load
'backports/std_lib'.
Forcing incompatibilities
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:
Hash
select(returns a Hash instead of an Array)
Enumerable / Array
map(returns an enumerator when called without a block)
String
length,size(for UTF-8 support)
These must be imported in addition to the backports gem, for example:
require "backports/force/hash_select"
{}.select{} # => {}, even in Ruby 1.8
Thanks
Thanks for the bug reports and patches, in particular the repeat offenders:
Arto Bendiken ( bendiken )
Konstantin Haase ( rkh )
Roger Pack ( rdp )
Victor Shepelev ( zverok )
Contributing
The best way to submit a patch is to also submit a patch to
ruby/spec and then a patch to backports that
make it pass the spec.
See below to test rubyspec. Note that only features missing from your Ruby
version are tested.
git submodule init && git submodule update # => pulls rubyspecs
bundle install
bundle exec rake spec[hash/slice] # => tests Hash#slice (must be in Ruby 2.4 or less)
bundle exec rake spec[hash/*] # => tests all backported Hash methods
bundle exec rake spec (or rake spec[*/*]) # => all rubyspecs for backported methods
Failures that are acceptable are added the to tags file.
License
backports is released under the terms of the MIT License, see the included
LICENSE file.
Author
: Marc-André Lafortune
Owner metadata
- Name: Marc-André Lafortune
- Login: marcandre
- Email: github@marc-andre.ca
- Kind: user
- Description: ♥ Elixir ♥ Ruby ♥ TypeScript ♥ Core team of Ruby, RuboCop. Author of Backports, Maintainer of Parsley.js, Featherlight.js.
- Website: blog.marc-andre.ca
- Location: Montreal, Canada
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/33770?v=4
- Repositories: 180
- Last ynced at: 2025-12-31T09:23:04.707Z
- Profile URL: https://github.com/marcandre
GitHub Events
Total
- Issues event: 4
- Watch event: 8
- Issue comment event: 8
- Push event: 5
- Pull request event: 3
- Fork event: 1
- Create event: 2
Last Year
- Issues event: 3
- Watch event: 6
- Issue comment event: 8
- Push event: 5
- Pull request event: 3
- Fork event: 1
- Create event: 2
Committers metadata
Last synced: about 21 hours ago
Total Commits: 705
Total Committers: 30
Avg Commits per committer: 23.5
Development Distribution Score (DDS): 0.082
Commits in past year: 8
Committers in past year: 3
Avg Commits per committer in past year: 2.667
Development Distribution Score (DDS) in past year: 0.375
| Name | Commits | |
|---|---|---|
| Marc-Andre Lafortune | g****b@m****a | 647 |
| zverok | z****e@g****m | 10 |
| Maxime Lapointe | h****n@h****m | 6 |
| Konstantin Haase | k****s@g****m | 5 |
| Arto Bendiken | a****o@b****t | 3 |
| Charles Oliver Nutter | h****s@h****m | 3 |
| Sylvain Joyeux | s****x@m****g | 3 |
| Alexey Zapparov | a****y@z****m | 2 |
| Benoit Daloze | e****p@g****m | 2 |
| Brent Cook | b****b@g****m | 2 |
| Stanisław Pitucha | s****a@e****m | 2 |
| Vladimir Dementyev | d****m@g****m | 2 |
| Elia Schito | e****a@s****e | 1 |
| Holger Just | h****r@p****m | 1 |
| Iain Beeston | i****n@g****m | 1 |
| Jon Wood | j****n@n****k | 1 |
| Justin Searls | s****s@g****m | 1 |
| Nic Benders | n****c@n****m | 1 |
| Onni Hakala | o****i@k****o | 1 |
| Peter Goldstein | p****n@g****m | 1 |
| Rumble Huang | b****0@n****w | 1 |
| Stefan Schüßler | m****l@s****e | 1 |
| T. Yama | c****n@g****m | 1 |
| Thomas Roehr | t****r@d****e | 1 |
| Thomas Walpole | t****e@g****m | 1 |
| Timo Schilling | t****o@s****o | 1 |
| Tyler Knappe | t****e@g****m | 1 |
| Willibaur | w****a@g****m | 1 |
| Yousuf Jukaku | y****u@l****m | 1 |
| jeremyredhead | j****d | 1 |
Committer domains:
- levelsetsolutions.com: 1
- schilling.io: 1
- dfki.de: 1
- stefanschuessler.de: 1
- ntu.edu.tw: 1
- keksi.io: 1
- newrelic.com: 1
- ninjagiraffes.co.uk: 1
- planio.com: 1
- schito.me: 1
- envato.com: 1
- zapparov.com: 1
- m4x.org: 1
- headius.com: 1
- bendiken.net: 1
- marc-andre.ca: 1
Issue and Pull Request metadata
Last synced: 22 days ago
Total issues: 41
Total pull requests: 74
Average time to close issues: about 1 year
Average time to close pull requests: 12 days
Total issue authors: 31
Total pull request authors: 26
Average comments per issue: 2.85
Average comments per pull request: 1.62
Merged pull request: 59
Bot issues: 0
Bot pull requests: 0
Past year issues: 2
Past year pull requests: 2
Past year average time to close issues: about 4 hours
Past year average time to close pull requests: 1 day
Past year issue authors: 2
Past year pull request authors: 1
Past year average comments per issue: 2.0
Past year average comments per pull request: 5.5
Past year merged pull request: 2
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- marcandre (4)
- zverok (4)
- headius (3)
- cielavenir (2)
- utkarsh2102 (2)
- rdp (1)
- ashmaroli (1)
- swedebugia (1)
- gintrator (1)
- bquorning (1)
- daBee (1)
- maisumakun (1)
- mtasaka (1)
- dkubb (1)
- sferik (1)
Top Pull Request Authors
- marcandre (32)
- zverok (5)
- MaxLap (5)
- headius (4)
- busterb (2)
- viraptor (2)
- sos4nt (2)
- ixti (2)
- eregon (2)
- palkan (2)
- timoschilling (1)
- jeremyredhead (1)
- 2maz (1)
- shugo (1)
- elia (1)
Top Issue Labels
- patch needed (3)
Top Pull Request Labels
Package metadata
- Total packages: 5
-
Total downloads:
- rubygems: 291,533,206 total
- Total docker downloads: 1,710,749,516
- Total dependent packages: 160 (may contain duplicates)
- Total dependent repositories: 43,955 (may contain duplicates)
- Total versions: 478
- Total maintainers: 1
gem.coop: backports
Essential backports that enable many of the nice features of Ruby for earlier versions.
- Homepage: http://github.com/marcandre/backports
- Documentation: http://www.rubydoc.info/gems/backports/
- Licenses: MIT
- Latest release: 3.25.3 (published 22 days ago)
- Last Synced: 2026-01-05T09:02:41.327Z (2 days ago)
- Versions: 142
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 145,699,758 Total
- Docker Downloads: 855,374,758
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.056%
- Docker downloads count: 0.061%
- Downloads: 0.164%
- Maintainers (1)
rubygems.org: backports
Essential backports that enable many of the nice features of Ruby for earlier versions.
- Homepage: http://github.com/marcandre/backports
- Documentation: http://www.rubydoc.info/gems/backports/
- Licenses: MIT
- Latest release: 3.25.3 (published 22 days ago)
- Last Synced: 2026-01-05T09:02:23.872Z (2 days ago)
- Versions: 142
- Dependent Packages: 158
- Dependent Repositories: 43,955
- Downloads: 145,699,758 Total
- Docker Downloads: 855,374,758
-
Rankings:
- Downloads: 0.132%
- Docker downloads count: 0.137%
- Dependent repos count: 0.16%
- Dependent packages count: 0.219%
- Average: 1.163%
- Stargazers count: 2.743%
- Forks count: 3.59%
- Maintainers (1)
gem.coop: marcandre-backports
Essential backports that enable some of the really nice features of ruby 1.8.7, ruby 1.9 and rails from ruby 1.8.6 and earlier.
- Homepage: http://github.com/marcandre/backports
- Documentation: http://www.rubydoc.info/gems/marcandre-backports/
- Licenses: mit
- Latest release: 1.9.0 (published over 11 years ago)
- Last Synced: 2026-01-04T20:02:50.537Z (2 days ago)
- Versions: 22
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 66,845 Total
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 4.009%
- Downloads: 12.028%
proxy.golang.org: github.com/marcandre/backports
- Homepage:
- Documentation: https://pkg.go.dev/github.com/marcandre/backports#section-documentation
- Licenses: mit
- Latest release: v3.25.3+incompatible (published 22 days ago)
- Last Synced: 2026-01-04T20:02:51.933Z (2 days ago)
- Versions: 150
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Stargazers count: 2.798%
- Forks count: 3.257%
- Average: 6.608%
- Dependent packages count: 9.576%
- Dependent repos count: 10.802%
rubygems.org: marcandre-backports
Essential backports that enable some of the really nice features of ruby 1.8.7, ruby 1.9 and rails from ruby 1.8.6 and earlier.
- Homepage: http://github.com/marcandre/backports
- Documentation: http://www.rubydoc.info/gems/marcandre-backports/
- Licenses: mit
- Latest release: 1.9.0 (published over 11 years ago)
- Last Synced: 2026-01-04T20:02:50.543Z (2 days ago)
- Versions: 22
- Dependent Packages: 2
- Dependent Repositories: 0
- Downloads: 66,845 Total
-
Rankings:
- Stargazers count: 2.544%
- Forks count: 3.286%
- Dependent packages count: 5.227%
- Downloads: 11.297%
- Average: 13.827%
- Dependent repos count: 46.782%
Dependencies
- activesupport ~> 3.2.0 development
- mspec >= 0 development
- rake >= 0 development
- rubocop < 1.13.0 development
- test-unit >= 0 development
- actions/checkout v2 composite
- ruby/setup-ruby v1 composite
Score: 30.92356712945726