pax_global_header 0000666 0000000 0000000 00000000064 12557303652 0014522 g ustar 00root root 0000000 0000000 52 comment=54941c9203a6694f4c21141572e1d1c8f8dc38ac
backports-3.6.6/ 0000775 0000000 0000000 00000000000 12557303652 0013526 5 ustar 00root root 0000000 0000000 backports-3.6.6/.document 0000664 0000000 0000000 00000000102 12557303652 0015336 0 ustar 00root root 0000000 0000000 lib/**/*.rb
bin/*
features/**/*.feature
-
README.rdoc
LICENSE.txt
backports-3.6.6/.gitignore 0000664 0000000 0000000 00000000062 12557303652 0015514 0 ustar 00root root 0000000 0000000 *.sw?
*.rbc
.DS_Store
coverage
rdoc
pkg
assets
rs
backports-3.6.6/.gitmodules 0000664 0000000 0000000 00000000140 12557303652 0015676 0 ustar 00root root 0000000 0000000 [submodule "spec/rubyspec"]
path = spec/rubyspec
url = git://github.com/rubyspec/rubyspec.git
backports-3.6.6/.irbrc 0000664 0000000 0000000 00000000023 12557303652 0014623 0 ustar 00root root 0000000 0000000 $:.unshift "./lib"
backports-3.6.6/.travis.yml 0000664 0000000 0000000 00000000526 12557303652 0015642 0 ustar 00root root 0000000 0000000 ---
language: ruby
rvm:
- "1.8.7"
- "1.9.2"
- "1.9.3"
- "2.0.0"
- "2.1.0"
- ruby-head
- jruby-18mode
- jruby-19mode
- rbx-18mode
- rbx-19mode
matrix:
allow_failures:
- rvm: jruby-18mode
- rvm: jruby-19mode
- rvm: rbx-18mode
- rvm: rbx-19mode
before_install:
- git submodule update --init --recursive
backports-3.6.6/CHANGELOG.rdoc 0000664 0000000 0000000 00000020353 12557303652 0015671 0 ustar 00root root 0000000 0000000 = Backports --- History
== Version 3.6.0 - February 14th, 2014
* Additional features of 2.1.0
* Bignum#bit_length
* Fixnum#bit_length
* Module#include (now public)
== Version 3.5.0 - February 3rd, 2014
* Additional features of 2.0.0
* Range#size
== Version 3.4.0 - December 29th, 2013
* Additional features of 2.1.0
* Array#to_h, Enumerable#to_h
== Version 3.3.0 - April 3rd, 2013
* Moved `Proc#yield` & `Hash#key` from 1.8.7 to 1.9.1
== Version 3.2.0 - April 2nd, 2013
* Moved `Dir.mktmpdir` to the stdlib 'tmpdir' for Ruby 1.8.7
* Removed `returning` as it is no longer part of Rails.
== Version 3.1.0 - March 5th, 2013
* Backports can now be loaded separately!
* Small tweaks and fixes for many methods to pass more RubySpecs
== Version 3.0.0 - February 24th, 2013
* Features of 2.0.0 are now required when requiring 'backports'.
* Additional features of 2.0.0
* Struct#to_h, NilClass#to_h, Hash#to_h
* Hash#default_proc = nil
* OpenStruct lib
* 1.8.7's Enumerator#with_index (it wasn't in the 1.8.7 NEWS file...)
== Version 2.8.0 - February 3rd, 2013
* Added some features of 2.0.0 (must be required explicitly until official release):
* Array#bsearch
* Range#bsearch
== Version 2.7.0 - January 14th, 2013
* Added some features of 2.0.0 (must be required explicitly until official release):
* Enumerable#lazy
* Enumerator::Lazy
== Version 2.6.0 - May 29th, 2012
* Removed Enumerable#join
== Version 2.5.0 - March 25th, 2012
* Added some features of 1.9.3:
* IO::NULL
* IO#advise
* String#byteslice
* String#prepend
== Version 2.4.0 - March 24th, 2012
* Add backporting for libraries
* Bring libraries up to date:
* Matrix
* Prime
* Set
* Added some features of 1.9.3:
* IO.write, IO.binwrite
* Add forcing backports (must be required explicitly):
* 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)
== Version 2.3.0 - May 13th, 2011
* Added Enumerator::Yielder#<<
== Version 2.2.0 - May 13th, 2011
* Ruby 1.8.8 was officially cancelled; code was moved to Ruby 1.9.1 and README updated.
* "".ord now raises an error.
== Version 2.1.0 - April 16th, 2011
* Proc#curry, #lambda (thanks Konstantine Haase)
== Version 2.0.0 - December 5th, 2010
Change of major version because of two small changes that are not quite compatible and because the minor version was getting quite high!
* Remove attempt at faking the new method missing. Unless you used `respond_to_missing` *and* `method(:some_method_handled_with_method_missing)`, you won't see a difference, except better performance (see issue #32) and this fixes some errors (see issue #34)
* Change behavior of array.flatten(0) to match Ruby 1.9 (i.e. return a dup of array, instead of array itself)
== Version 1.18.0 - June 19th, 2010
* Added some features of 1.9.1:
* Math#log2, Math#log with base
* Also fixed Enumerator#each in 1.8.6.
== Version 1.17.0 - May 17th, 2010
* Added some features of 1.9.2:
* Array#repeated_combination, #repeated_permutation
== Version 1.16.2 - April 11th, 2010
* Added some features of 1.9.2:
* Array#uniq, #uniq! (with block)
* Array#product (with block)
* Dir.home
* Hash#keep_if, select!
* Random (new class)
== Version 1.15.0 - March 23rd, 2010
* Added a features of 1.9.2:
* Object#singleton_class
== Version 1.14.0 - March 3rd, 2010
* Added some features of 1.9.2:
* Array#rotate, rotate!
* Array#keep_if, select!
* Array#sort_by!
* Enumerable#join
* Enumerable#slice_before
* Float::INFINITY, NAN
* MatchData#==
== Version 1.13.0 - January 20th, 2010
* Missing for 1.8.7 were
* Array#permutation
* Hash#hash (was only inherited)
* Hash#eql? (was only inherited)
== Version 1.12.0 - December 4th, 2009
* Finer grain includes (see README)
require "backports/1.9" # requires all ruby backports
require "backports/1.9.1" # requires all ruby backports up to 1.9.1 (but not 1.9.2)
* Backported all builtin methods of 1.8.8 (most of which where moved from the 1.9 backports)
* Refreshed README
== Version 1.11.0 - November 4th, 2009
* Added Enumerable#flat_map / collect_concat (Ruby 1.9)
* Added Object#public_send (Ruby 1.9)
* Added Object#public_method (Ruby 1.9)
* bug fixes
== Version 1.10.0 - September 29th, 2009
* Added Enumerable#chunk (Ruby 1.9)
* Added Kernel#respond_to_missing? (Ruby 1.9)
* Completed Process.exec (Ruby 1.8.7)
== Version 1.9.0 - September 4th, 2009
* In Ruby 1.9, most class methods of File accept filenames as String, or convertible via #to_str or #to_path.
File#to_path is also an alias to File#path. These have been backported.
* File.binread (actually IO.binread)
* BasicObject available via "require 'backports/basic_object"
== Version 1.8.4 - September 3rd, 2009
Added Dir.mktmpdir for older version of 1.8.6
== Version 1.8.1 - September 1st, 2009
Added the alias String#lines (Ruby 1.8.7)
== Version 1.8 - August 30, 2009
Backports can be required selectively:
* backports/1.8.7
* backports/1.9 (which include 1.8.7)
* rails
== Version 1.8 - August 30, 2009
Backports can be required selectively:
* backports/1.8.7
* backports/1.9 (which include 1.8.7)
* rails
== Version 1.7.1 - August 20, 2009
Enumerable#take and Enumerable#first(n) are now returning as soon as possible. Previously, #each was yielding one element too many. See redmine issue #1554.
== Version 1.7 - May 27, 2009
Porting all 1.8.7 features to rubinius was quite enlightening (http://blog.marc-andre.ca/2009/05/schizo-ruby-puzzle.html ).
Many improvements were made to be consistent with MRI, e.g. converting arguments using to_int if needed, etc...
The changes are now reflected in 'backports'.
Some IO and ARGF methods were missing and are now complete.
== Version 1.6.6 - April 30, 2009
Important bug fix. String#gsub is left alone until I find a good way to modify it.
== Version 1.6 - April 29, 2009
Completed backport to 1.8.7.
* Array
* extract_options!
* Binding
* +eval+
* Dir
* +each+, +foreach+
* Enumerator
* +new+
* +with_object+
* +next+, +rewind+
* Hash
* Optional block for delete_if, each, each_key, each_pair, each_value, reject!, select (and ENV)
* Integer
* moved stuff out of Fixnum
* Optional block for +downto+, +times+, +upto+
* IO
* Optional block for +each+, +each_line+, +each_byte+, +foreach+ (and ARGF)
* Kernel
* +loop+, +StopIteration+
* +__method__+, +__callee__+
* Method
* +name+, +owner+, +receiver+
* Module
* +class_exec+, +module_exec+
* Numeric
* +step+
* Object
* +define_singleton_method+
* +instance_exec+
* ObjectSpace
* +each_object+
* Range
* Optional block for +each+, +step+
* Regexp
* +union+
* String
* +try_convert+
* ascii_only?
* +bytesize+
* +chr+
* +clear+
* +codepoints+, +each_codepoint+
* +stringify_keys+, +stringify_keys!+
* +each+, +each_line+, +each_byte+
* +gsub+
* +upto+
* Struct
* +each+, +each_pair+
* Symbol
* <=>, +casecmp+
* +capitalize+, +downcase+, +next+, +succ+, +swapcase+, +upcase+
* =~, [], empty?, length, match, size
* UnboundMethod
* +name+, +owner+
== Version 1.5 - April 24, 2009
* Array (completed)
* +combination+
* +try_convert+
* Optional block for collect!, :map!, :each, :each_index, :reject, :reject!, :delete_if
* +pop+, +shift+
* +product+
* Fixnum (completed)
* +div+, +fdiv+
* +succ+
* +magnitude+
* Enumerable (completed)
* +each_with_object+
* +inject+
* +max_by+, +min_by+, +minmax+, +minmax_by+
* +reduce+
* +to_a+
== Version 1.4 - April 21, 2009
* String
* +rpartition+
* Proc
* +yield+
== Version 1.3 - April 17, 2009
* Enumerable
* none?
* Array
* +sample+, +shuffle+, +shuffle!+
* String
* +each_char+, +chars+
* +partition+
Tests and fixes for String#start_with? and String#end_with?
== Version 1.2 - April 12, 2009
* Array
* +reverse_each+
* +cycle+
* Enumerable
* +reverse_each+
* +each_slice+, +each_cons+
* +count+
* +cycle+
* +group_by+
* Hash
* default_proc=
== Version 1.1 - April 11, 2009
* Array
* +flatten+, flatten!
* +find_index+, +index+
* Hash
* +reverse_merge+, reverse_merge!
== Version 1.0 - April 2nd, 2009
=== Initial release.
backports-3.6.6/Gemfile 0000664 0000000 0000000 00000001430 12557303652 0015017 0 ustar 00root root 0000000 0000000 source "http://rubygems.org"
# Declare your gem's dependencies in backports.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# jquery-rails is used by the dummy application
group :test do
gem "rake"
gem 'mspec', :git => 'git://github.com/rubyspec/mspec.git'
gem 'activesupport'
gem 'minitest', '< 5.0.0', :require => false
gem 'test-unit'
end
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
backports-3.6.6/Gemfile.lock 0000664 0000000 0000000 00000001007 12557303652 0015746 0 ustar 00root root 0000000 0000000 GIT
remote: git://github.com/rubyspec/mspec.git
revision: 69c388b1187789f4996eda7dec4c1404fcd6b742
specs:
mspec (1.5.18)
PATH
remote: .
specs:
backports (3.6.6)
GEM
remote: http://rubygems.org/
specs:
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
i18n (0.6.1)
minitest (4.7.5)
multi_json (1.7.2)
rake (10.1.0)
test-unit (2.1.1.0)
PLATFORMS
java
ruby
DEPENDENCIES
activesupport
backports!
minitest (< 5.0.0)
mspec!
rake
test-unit
backports-3.6.6/LICENSE.txt 0000664 0000000 0000000 00000002050 12557303652 0015346 0 ustar 00root root 0000000 0000000 Copyright (c) 2009 Marc-Andre Lafortune
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
backports-3.6.6/README.rdoc 0000664 0000000 0000000 00000021633 12557303652 0015341 0 ustar 00root root 0000000 0000000 = Backports Library {
}[https://travis-ci.org/marcandre/backports] {
}[http://badge.fury.io/rb/backports] {
[42].sample rescue "dum example" will return "dum example" without this gem and 42 with it.
A real incompatibility is, 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)
All features of 1.8.7 are backported (well, almost all, see the exception list bellow), and many of the following versions up to 2.1
For historical reasons, some generic and self-contained features of active-support are also included. By simple I mean that String#camelcase is there, but #pluralize isn't. These will probably be removed in the future, so it's recommended to require those directly from active_support.
== Installation & compatibility
+backports+ is can be installed with:
(sudo) 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
# Or for all backports
require 'backports'
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 1.8.6, 1.8.7, 1.9.1, 1.9.2, 1.9.3, 2.0, 2.1, JRuby and Rubinius.
= Complete List of backports
== Ruby 2.1 backports
* Array
* +to_h+
* Bignum
* +bit_length+
* Enumerable
* +to_h+
* Fixnum
* +bit_length+
* Module
* +include+ (now public)
== 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
* +byteslice+
* +prepend+
== Ruby 1.9.2 backports
* Array
* rotate, rotate!
* keep_if, select!
* +product+ (with block)
* +repeated_combination+, +repeated_permutation+
* sort_by!
* uniq, uniq! (with block)
* Complex
* +to_r+
* Dir
* +home+
* Enumerable
* +chunk+
* +flat_map+, +collect_concat+
* +join+
* +slice_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'. The implementation is also available with require 'backports/random/implementation'.
== Ruby 1.9.1 backports
Additionally, the following Ruby 1.9 features have been backported:
* Array
* +try_convert+
* +sample+
* Enumerable
* +each_with_object+
* +each_with_index+ (with arguments)
* Enumerator
* +new+ (with block)
* File
* +binread+
* +to_path+
* All class methods accepting filenames will accept files or anything with a #to_path method.
* File.open accepts an options hash.
* Float
* +round+
* Hash
* +assoc+, +rassoc+
* +key+
* +try_convert+
* default_proc=
* Integer
* +magnitude+
* +round+
* IO
* +bin_read+
* +try_convert+
* +ungetbyte+
* IO.open accepts an options hash.
* Kernel
* +require_relative+
* Math
* +log+ (with base)
* +log2+
* Numeric
* +round+
* Object
* +define_singleton_method+
* +public_method+
* +public_send+
* Proc
* +yield+
* +lambda?+
* +curry+
* ===
* Range
* cover?
* Regexp
* +try_convert+
* String
* ascii_only?
* +chr+
* +clear+
* +codepoints+, +each_codepoint+
* +get_byte+, +set_byte+
* +ord+
* +try_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[https://github.com/ruby/ruby/blob/ruby_1_8_7/NEWS]. 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 are slowly being backported. You simply require them as usual after requiring 'backports/std_lib'. Requiring 'backports/std_lib' after the standard libraries is also supported.
require "backports/std_lib"
require "prime"
42.prime? # => false, even in Ruby 1.8.x
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 the whole of 'backports', or all 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[http://github.com/bendiken] )
* Konstantin Haase ( rkh[https://github.com/rkh])
* Roger Pack ( rdp[http://github.com/rdp] )
The best way to submit a patch is to also submit a patch to RubySpec[https://github.com/rubyspec/rubyspec] and then a patch to backports that make it pass the spec. To test rubyspec:
git submodule init && git submodule update # => pulls rubyspecs
rake spec[array/bsearch] # => tests Array#bsearch
rake spec[array/*] # => tests all backported Array methods
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
backports-3.6.6/Rakefile 0000664 0000000 0000000 00000007373 12557303652 0015205 0 ustar 00root root 0000000 0000000 begin
require "bundler/gem_tasks"
rescue LoadError
# bundler not installed
end
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = false
end
desc "Run specs, where path can be '*/*' (default), 'class/*' or 'class/method'."
task :spec, :path, :action do |t, args|
args.with_defaults(:path => '*/*', :action => 'ci')
stats = [[0] * 5]
not_found = []
mspec_cmds(args[:path], args[:action]) do |cmd, path|
result = `#{cmd}`
match = result.match(/(\d+) files?, (\d+) examples?, (\d+) expectations?, (\d+) failures?, (\d+) errors?/)
if match.nil?
puts "*** mspec returned with unexpected results:"
puts result
puts "Command was:", cmd
fail "Unexpected output from mspec"
end
_, ex, p, f, e = data = match.captures.map{|x| x.to_i}
not_found << path if ex == 0
stats << data
if f + e > 0
puts cmd
puts result
else
print "."
STDOUT.flush
end
end
$:.unshift 'lib'
require 'backports/rails'
_, ex, p, f, e = stats = stats.transpose.map{|x| x.sum}
puts "*** Overall:", stats.zip(%w[files examples expectations failures errors]).map{|a| a.join(' ')}.join(', ')
puts "No spec found for #{not_found.join(', ')}" unless not_found.empty?
fail unless f + e == 0
end
task :all_spec do # Necessary because of argument passing bug in 1.8.7
Rake::Task[:spec].invoke
end
task :spec_tag, :path do |t, args|
Rake::Task[:spec].invoke(args[:path], 'tag -G fails')
end
task :default => [:test, :all_spec]
DEPENDENCIES = Hash.new([]).merge!(
'1.8.7/argf/chars' => 'backports/1.8.7/string/each_char',
'1.8.7/argf/each_char' => 'backports/1.8.7/string/each_char',
'1.8.7/array/cycle' => 'backports/1.8.7/stop_iteration',
'1.8.7/enumerable/entries' => ['backports/1.8.7/enumerable/each_with_index', 'backports/1.8.7/enumerable/to_a'],
'1.8.7/enumerator/rewind' => 'backports/1.8.7/enumerator/next',
'1.8.7/hash/reject' => 'backports/1.8.7/integer/even',
'1.9.1/hash/rassoc' => 'backports/1.9.1/hash/key',
'1.9.1/proc/lambda' => 'backports/1.9.1/proc/curry',
'1.9.2/complex/to_r' => 'complex',
'1.9.2/array/select' => 'backports/1.8.7/array/select',
'1.9.2/hash/select' => 'backports/1.8.7/hash/select',
'1.9.2/enumerable/each_entry' => 'backports/1.8.7/enumerable/each_with_index',
'2.0.0/hash/to_h' => 'backports/1.9.1/hash/default_proc'
)
{
:each_with_index => %w[enumerable/detect enumerable/find enumerable/find_all enumerable/select enumerable/to_a],
:first => %w[enumerable/cycle io/bytes io/chars io/each_byte io/each_char io/lines io/each_line]
}.each do |req, libs|
libs.each{|l| DEPENDENCIES["1.8.7/#{l}"] = "backports/1.8.7/enumerable/#{req}" }
end
# These cause actual errors while loading in 1.8:
IGNORE_IN_18 = %w[
1.9.1/symbol/length
1.9.1/symbol/size
1.9.3/string/byteslice
1.8.7/proc/yield
1.9.1/proc/case_compare
]
def mspec_cmds(pattern, action='ci')
pattern = "lib/backports/*.*.*/#{pattern}.rb"
Dir.glob(pattern) do |lib_path|
_match, version, path = lib_path.match(/backports\/(\d\.\d\.\d)\/(.*)\.rb/).to_a
next if path =~ /stdlib/
next if version <= RUBY_VERSION
version_path = "#{version}/#{path}"
next if IGNORE_IN_18.include? version_path if RUBY_VERSION < '1.9'
deps = [*DEPENDENCIES[version_path]].map{|p| "-r #{p}"}.join(' ')
klass, method = path.split('/')
path = [klass.gsub('_', ''), method].join('/') # don't ask me why RubySpec uses matchdata instead of match_data
yield %W[mspec #{action}
-I lib
-r ./set_version/#{version}
#{deps}
-r backports/#{version_path}
spec/rubyspec/core/#{path}_spec.rb
].join(' '), path
end
end
backports-3.6.6/backports.gemspec 0000664 0000000 0000000 00000001546 12557303652 0017071 0 ustar 00root root 0000000 0000000 # -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'backports/version'
Gem::Specification.new do |gem|
gem.name = "backports"
gem.version = Backports::VERSION
gem.authors = ["Marc-André Lafortune"]
gem.email = ["github@marc-andre.ca"]
gem.description = %q{Essential backports that enable many of the nice features of Ruby 1.8.7 up to 2.1.0 for earlier versions.}
gem.summary = %q{Backports of Ruby features for older Ruby.}
gem.homepage = "http://github.com/marcandre/backports"
gem.license = "MIT"
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
end
backports-3.6.6/default.mspec 0000664 0000000 0000000 00000000600 12557303652 0016177 0 ustar 00root root 0000000 0000000 if (Backports::TARGET_VERSION rescue false) # Conf loaded at different times, not sure why
class MSpecScript
# The set of substitutions to transform a spec filename
# into a tag filename.
set :tags_patterns, [ [%r(rubyspec/), "tags/#{RUBY_VERSION}/"] ]
end
SpecGuard.ruby_version_override = Backports::TARGET_VERSION if Backports::TARGET_VERSION > RUBY_VERSION
end
backports-3.6.6/lib/ 0000775 0000000 0000000 00000000000 12557303652 0014274 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports.rb 0000664 0000000 0000000 00000000150 12557303652 0016605 0 ustar 00root root 0000000 0000000 require "backports/tools"
require "backports/version"
require "backports/2.1"
require "backports/rails"
backports-3.6.6/lib/backports/ 0000775 0000000 0000000 00000000000 12557303652 0016264 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7.rb 0000664 0000000 0000000 00000000221 12557303652 0017257 0 ustar 00root root 0000000 0000000 # require this file to load all the backports of Ruby 1.8.7
require "backports/tools"
require "backports/std_lib"
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/ 0000775 0000000 0000000 00000000000 12557303652 0016737 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/argf.rb 0000664 0000000 0000000 00000000117 12557303652 0020202 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/argf/ 0000775 0000000 0000000 00000000000 12557303652 0017656 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/argf/bytes.rb 0000664 0000000 0000000 00000000051 12557303652 0021325 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/argf/each_byte'
backports-3.6.6/lib/backports/1.8.7/argf/chars.rb 0000664 0000000 0000000 00000000051 12557303652 0021277 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/argf/each_char'
backports-3.6.6/lib/backports/1.8.7/argf/each.rb 0000664 0000000 0000000 00000000203 12557303652 0021076 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional ARGF, :each, :force => true if RUBY_VERSION < '1.8.7'
backports-3.6.6/lib/backports/1.8.7/argf/each_byte.rb 0000664 0000000 0000000 00000000315 12557303652 0022125 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.8.7'
require 'backports/tools/make_block_optional'
class << ARGF
Backports.make_block_optional ARGF, :each_byte, :force => true
alias_method :bytes, :each_byte
end
end
backports-3.6.6/lib/backports/1.8.7/argf/each_char.rb 0000664 0000000 0000000 00000001465 12557303652 0022106 0 ustar 00root root 0000000 0000000 unless ARGF.respond_to? :each_char
require 'backports/tools/alias_method'
require 'enumerator'
class << ARGF
def each_char
return to_enum(:each_char) unless block_given?
if $KCODE == "UTF-8"
lookup = 7.downto(4)
while c = read(1) do
n = c[0]
leftmost_zero_bit = lookup.find{|i| n[i].zero? }
case leftmost_zero_bit
when 7 # ASCII
yield c
when 6 # UTF 8 complementary characters
next # Encoding error, ignore
else
more = read(6-leftmost_zero_bit)
break unless more
yield c+more
end
end
else
while s = read(1)
yield s
end
end
self
end
Backports.alias_method self, :chars, :each_char
end
end
backports-3.6.6/lib/backports/1.8.7/argf/each_line.rb 0000664 0000000 0000000 00000000210 12557303652 0022103 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional ARGF, :each_line, :force => true if RUBY_VERSION < '1.8.7'
backports-3.6.6/lib/backports/1.8.7/argf/getbyte.rb 0000664 0000000 0000000 00000000151 12557303652 0021643 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
class << ARGF
Backports.alias_method self, :getbyte, :getc
end
backports-3.6.6/lib/backports/1.8.7/argf/lines.rb 0000664 0000000 0000000 00000000137 12557303652 0021316 0 ustar 00root root 0000000 0000000 require 'backports/tools'
class << ARGF
Backports.alias_method self, :lines, :each_line
end
backports-3.6.6/lib/backports/1.8.7/argf/readbyte.rb 0000664 0000000 0000000 00000000156 12557303652 0022004 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
class << ARGF
Backports.alias_method self, :readbyte, :readchar
end
backports-3.6.6/lib/backports/1.8.7/array.rb 0000664 0000000 0000000 00000000117 12557303652 0020401 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/array/ 0000775 0000000 0000000 00000000000 12557303652 0020055 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/array/collect.rb 0000664 0000000 0000000 00000000160 12557303652 0022024 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Array, :collect!, :test_on => [42]
backports-3.6.6/lib/backports/1.8.7/array/combination.rb 0000664 0000000 0000000 00000001720 12557303652 0022704 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :combination
require 'backports/tools/arguments'
require 'enumerator'
class Array
def combination(num)
num = Backports.coerce_to_int(num)
return to_enum(:combination, num) unless block_given?
return self unless (0..size).include? num
# Implementation note: slightly tricky.
# Example: self = 1..7, num = 3
picks = (0...num).to_a # picks start at 0, 1, 2
max_index = ((size-num)...size).to_a # max (index for a given pick) is [4, 5, 6]
pick_max_pairs = picks.zip(max_index).reverse # pick_max_pairs = [[2, 6], [1, 5], [0, 4]]
leave = Proc.new{return self}
loop do
yield values_at(*picks)
move = pick_max_pairs.find(leave){|pick, max| picks[pick] < max}.first
new_index = picks[move] + 1
picks[move...num] = (new_index...(new_index+num-move)).to_a
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/array/cycle.rb 0000664 0000000 0000000 00000000527 12557303652 0021505 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :cycle
require 'backports/tools/arguments'
class Array
def cycle(n = nil)
return to_enum(:cycle, n) unless block_given?
if n.nil?
each{|e| yield e } until false
else
n = Backports.coerce_to_int(n)
n.times{each{|e| yield e }}
end
nil
end
end
end
backports-3.6.6/lib/backports/1.8.7/array/delete_if.rb 0000664 0000000 0000000 00000000161 12557303652 0022320 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Array, :delete_if, :test_on => [42]
backports-3.6.6/lib/backports/1.8.7/array/each.rb 0000664 0000000 0000000 00000000154 12557303652 0021302 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Array, :each, :test_on => [42]
backports-3.6.6/lib/backports/1.8.7/array/each_index.rb 0000664 0000000 0000000 00000000162 12557303652 0022470 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Array, :each_index, :test_on => [42]
backports-3.6.6/lib/backports/1.8.7/array/find_index.rb 0000664 0000000 0000000 00000000046 12557303652 0022511 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/array/index'
backports-3.6.6/lib/backports/1.8.7/array/flatten.rb 0000664 0000000 0000000 00000002623 12557303652 0022042 0 ustar 00root root 0000000 0000000 unless ([[]].flatten(1) rescue false)
require 'backports/tools/alias_method_chain'
require 'backports/tools/arguments'
class Array
# Recursively flatten any contained Arrays into an one-dimensional result.
# Adapted from rubinius'
def flatten_with_optional_argument(level=-1)
dup.flatten!(level) || self
end
# Flattens self in place as #flatten. If no changes are
# made, returns nil, otherwise self.
# Adapted from rubinius'
def flatten_with_optional_argument!(level=-1)
level = Backports.coerce_to_int(level)
return flatten_without_optional_argument! if level < 0
out = []
ret = recursively_flatten_finite(self, out, level)
replace(out) if ret
ret
end
Backports.alias_method_chain self, :flatten, :optional_argument
Backports.alias_method_chain self, :flatten!, :optional_argument
# Helper to recurse through flattening
# Adapted from rubinius'; recursion guards are not needed because level is finite
def recursively_flatten_finite(array, out, level)
ret = nil
if level <= 0
out.concat(array)
else
array.each do |o|
if ary = Backports.is_array?(o)
recursively_flatten_finite(ary, out, level - 1)
ret = self
else
out << o
end
end
end
ret
end
private :recursively_flatten_finite
end
end
backports-3.6.6/lib/backports/1.8.7/array/index.rb 0000664 0000000 0000000 00000000731 12557303652 0021512 0 ustar 00root root 0000000 0000000 unless ([1].index{true} rescue false)
require 'backports/tools/alias_method_chain'
require 'enumerator'
class Array
def index_with_block(*arg)
return to_enum(:index_with_block) if arg.empty? && !block_given?
return index_without_block(*arg) unless block_given? && arg.empty?
each_with_index{|o,i| return i if yield o}
return nil
end
Backports.alias_method_chain self, :index, :block
alias_method :find_index, :index
end
end
backports-3.6.6/lib/backports/1.8.7/array/map.rb 0000664 0000000 0000000 00000000154 12557303652 0021157 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Array, :map!, :test_on => [42]
backports-3.6.6/lib/backports/1.8.7/array/permutation.rb 0000664 0000000 0000000 00000001467 12557303652 0022761 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :permutation
require 'backports/tools/arguments'
require 'enumerator'
class Array
def permutation(num = Backports::Undefined)
return to_enum(:permutation, num) unless block_given?
num = num.equal?(Backports::Undefined) ?
size :
Backports.coerce_to_int(num)
return self unless (0..size).include? num
final_lambda = lambda do |partial, remain|
yield partial
end
outer_lambda = (1..num).inject(final_lambda) do |proc, _|
lambda do |partial, remain|
remain.each_with_index do |val, i|
new_remain = remain.dup
new_remain.delete_at(i)
proc.call(partial.dup << val, new_remain)
end
end
end
outer_lambda.call([], dup)
end
end
end
backports-3.6.6/lib/backports/1.8.7/array/pop.rb 0000664 0000000 0000000 00000001016 12557303652 0021176 0 ustar 00root root 0000000 0000000 unless ([1].pop(1) rescue false)
require 'backports/tools/alias_method_chain'
require 'backports/tools/arguments'
class Array
def pop_with_optional_argument(n = Backports::Undefined)
return pop_without_optional_argument if n == Backports::Undefined
n = Backports.coerce_to_int(n)
raise ArgumentError, "negative array size" if n < 0
first = size - n
first = 0 if first < 0
slice!(first..size).to_a
end
Backports.alias_method_chain self, :pop, :optional_argument
end
end
backports-3.6.6/lib/backports/1.8.7/array/product.rb 0000664 0000000 0000000 00000001625 12557303652 0022066 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :product
require 'backports/tools/arguments'
class Array
def product(*arg)
# Implementation notes: We build a block that will generate all the combinations
# by building it up successively using "inject" and starting with one
# responsible to append the values.
#
result = []
arg.map!{|ary| Backports.coerce_to_ary(ary)}
n = arg.inject(size) { |p, a| p * a.size }
return [] if n == 0
raise RangeError, "too big a product" if n > 1<<31
arg.reverse! # to get the results in the same order as in MRI, vary the last argument first
arg.push self
outer_lambda = arg.inject(result.method(:push)) do |proc, values|
lambda do |partial|
values.each do |val|
proc.call(partial.dup << val)
end
end
end
outer_lambda.call([])
result
end
end
end
backports-3.6.6/lib/backports/1.8.7/array/reject.rb 0000664 0000000 0000000 00000000170 12557303652 0021654 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Array, :reject, :reject!, :test_on => [42]
backports-3.6.6/lib/backports/1.8.7/array/reverse_each.rb 0000664 0000000 0000000 00000000164 12557303652 0023036 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Array, :reverse_each, :test_on => [42]
backports-3.6.6/lib/backports/1.8.7/array/rindex.rb 0000664 0000000 0000000 00000000710 12557303652 0021671 0 ustar 00root root 0000000 0000000 unless ([1].rindex{true} rescue false)
class Array
require 'backports/tools/alias_method_chain'
require 'enumerator'
def rindex_with_block(*arg)
return to_enum(:rindex) if !block_given? && arg.empty?
return rindex_without_block(*arg) unless block_given? && arg.empty?
i = 0
reverse_each{|o| i += 1; return size - i if yield o}
return nil
end
Backports.alias_method_chain self, :rindex, :block
end
end
backports-3.6.6/lib/backports/1.8.7/array/select.rb 0000664 0000000 0000000 00000000156 12557303652 0021663 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Array, :select, :test_on => [42]
backports-3.6.6/lib/backports/1.8.7/array/shift.rb 0000664 0000000 0000000 00000000732 12557303652 0021521 0 ustar 00root root 0000000 0000000 unless ([1].shift(1) rescue false)
class Array
require 'backports/tools/alias_method_chain'
require 'backports/tools/arguments'
def shift_with_optional_argument(n = Backports::Undefined)
return shift_without_optional_argument if n == Backports::Undefined
n = Backports.coerce_to_int(n)
raise ArgumentError, "negative array size" if n < 0
slice!(0, n)
end
Backports.alias_method_chain self, :shift, :optional_argument
end
end
backports-3.6.6/lib/backports/1.8.7/array/shuffle.rb 0000664 0000000 0000000 00000000653 12557303652 0022042 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :shuffle
class Array
def shuffle
dup.shuffle!
end
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
def shuffle!
raise TypeError, "can't modify frozen array" if frozen?
size.times do |i|
r = i + Kernel.rand(size - i)
self[i], self[r] = self[r], self[i]
end
self
end
end
end
backports-3.6.6/lib/backports/1.8.7/binding.rb 0000664 0000000 0000000 00000000117 12557303652 0020675 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/binding/ 0000775 0000000 0000000 00000000000 12557303652 0020351 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/binding/eval.rb 0000664 0000000 0000000 00000000204 12557303652 0021621 0 ustar 00root root 0000000 0000000 unless Binding.method_defined? :eval
class Binding
def eval(expr, *arg)
Kernel.eval(expr, self, *arg)
end
end
end
backports-3.6.6/lib/backports/1.8.7/dir.rb 0000664 0000000 0000000 00000000117 12557303652 0020041 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/dir/ 0000775 0000000 0000000 00000000000 12557303652 0017515 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/dir/each.rb 0000664 0000000 0000000 00000000430 12557303652 0020737 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
begin
Backports.make_block_optional Dir, :each, :test_on => Dir.new('.')
rescue # We may not be able to read the current directory, issue #58
Backports.make_block_optional Dir, :each, :force => true if RUBY_VERSION < '1.8.7'
end
backports-3.6.6/lib/backports/1.8.7/dir/foreach.rb 0000664 0000000 0000000 00000000453 12557303652 0021453 0 ustar 00root root 0000000 0000000 require 'backports/tools'
class << Dir
begin
Backports.make_block_optional self, :foreach, :test_on => Dir, :arg => '.'
rescue # We may not be able to read the current directory, issue #58
Backports.make_block_optional self, :foreach, :force => true if RUBY_VERSION < '1.8.7'
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable.rb 0000664 0000000 0000000 00000000117 12557303652 0021402 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/enumerable/ 0000775 0000000 0000000 00000000000 12557303652 0021056 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/enumerable/count.rb 0000664 0000000 0000000 00000000574 12557303652 0022541 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :count
require 'backports/tools/arguments'
module Enumerable
def count(item = Backports::Undefined)
seq = 0
if item != Backports::Undefined
each { |o| seq += 1 if item == o }
elsif block_given?
each { |o| seq += 1 if yield(o) }
else
each { seq += 1 }
end
seq
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/cycle.rb 0000664 0000000 0000000 00000001065 12557303652 0022504 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :cycle
require 'backports/tools/arguments'
require 'enumerator'
module Enumerable
def cycle(n = nil)
return to_enum(:cycle, n) unless block_given?
n = n && Backports.coerce_to_int(n)
if n == nil || n >= 1
cache = []
each do |elem|
cache << elem
yield elem
end
if n
(n-1).times { cache.each{|e| yield e } }
else
loop { cache.each{|e| yield e } }
end unless cache.empty?
end
nil
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/detect.rb 0000664 0000000 0000000 00000000163 12557303652 0022653 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Enumerable, :detect, :test_on => 1..2
backports-3.6.6/lib/backports/1.8.7/enumerable/drop.rb 0000664 0000000 0000000 00000000467 12557303652 0022356 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :drop
require 'backports/tools/arguments'
module Enumerable
def drop(n)
n = Backports.coerce_to_int(n)
raise ArgumentError, "attempt to drop negative size" if n < 0
ary = to_a
return [] if n > ary.size
ary[n...ary.size]
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/drop_while.rb 0000664 0000000 0000000 00000000644 12557303652 0023543 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :drop_while
require 'enumerator'
module Enumerable
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
def drop_while
return to_enum(:drop_while) unless block_given?
ary = []
dropping = true
each do |obj|
ary << obj unless dropping &&= yield(obj)
end
ary
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/each_cons.rb 0000664 0000000 0000000 00000000303 12557303652 0023321 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
require 'enumerator' unless Enumerable.method_defined? :each_cons
Backports.make_block_optional Enumerable, :each_cons, :test_on => 1..2, :arg => 1
backports-3.6.6/lib/backports/1.8.7/enumerable/each_slice.rb 0000664 0000000 0000000 00000000305 12557303652 0023460 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
require 'enumerator' unless Enumerable.method_defined? :each_slice
Backports.make_block_optional Enumerable, :each_slice, :test_on => 1..2, :arg => 1
backports-3.6.6/lib/backports/1.8.7/enumerable/each_with_index.rb 0000664 0000000 0000000 00000000174 12557303652 0024527 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Enumerable, :each_with_index, :test_on => 1..2
backports-3.6.6/lib/backports/1.8.7/enumerable/entries.rb 0000664 0000000 0000000 00000000541 12557303652 0023054 0 ustar 00root root 0000000 0000000 if Enumerable.instance_method(:entries).arity.zero?
require 'backports/tools/alias_method_chain'
module Enumerable
def entries_with_optional_arguments(*args)
return entries_without_optional_arguments if args.empty?
to_enum(:each, *args).entries
end
Backports.alias_method_chain self, :entries, :optional_arguments
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/find.rb 0000664 0000000 0000000 00000000161 12557303652 0022321 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Enumerable, :find, :test_on => 1..2
backports-3.6.6/lib/backports/1.8.7/enumerable/find_all.rb 0000664 0000000 0000000 00000000165 12557303652 0023155 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Enumerable, :find_all, :test_on => 1..2
backports-3.6.6/lib/backports/1.8.7/enumerable/find_index.rb 0000664 0000000 0000000 00000000763 12557303652 0023520 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :find_index
require 'backports/tools/arguments'
require 'enumerator'
module Enumerable
def find_index(obj = Backports::Undefined)
if obj != Backports::Undefined
each_with_index do |element, i|
return i if element == obj
end
elsif block_given?
each_with_index do |element, i|
return i if yield element
end
else
return to_enum(:find_index)
end
nil
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/first.rb 0000664 0000000 0000000 00000001001 12557303652 0022522 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :first
require 'backports/tools/arguments'
module Enumerable
def first(n = Backports::Undefined)
if n == Backports::Undefined
each{|obj| return obj}
nil
else
n = Backports.coerce_to_int(n)
raise ArgumentError, "attempt to take negative size: #{n}" if n < 0
array = []
each do |elem|
array << elem
break if array.size >= n
end unless n == 0
array
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/group_by.rb 0000664 0000000 0000000 00000000446 12557303652 0023235 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :group_by
require 'enumerator'
module Enumerable
def group_by
return to_enum(:group_by) unless block_given?
result = {}
each do |o|
result.fetch(yield(o)){|key| result[key] = []} << o
end
result
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/inject.rb 0000664 0000000 0000000 00000000764 12557303652 0022666 0 ustar 00root root 0000000 0000000 unless ((1..2).inject(:+) rescue false)
require 'backports/tools/alias_method'
require 'backports/tools/alias_method_chain'
module Enumerable
def inject_with_symbol(*args, &block)
return inject_without_symbol(*args, &block) if block_given? && args.size <= 1
method = args.pop
inject_without_symbol(*args) {|memo, obj| memo.send(method, obj)}
end
Backports.alias_method_chain self, :inject, :symbol
end
Backports.alias_method Enumerable, :reduce, :inject
end
backports-3.6.6/lib/backports/1.8.7/enumerable/max_by.rb 0000664 0000000 0000000 00000000663 12557303652 0022667 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :max_by
require 'backports/tools/extreme_object'
require 'enumerator'
module Enumerable
def max_by
return to_enum(:max_by) unless block_given?
max_object, max_result = nil, Backports::MOST_EXTREME_OBJECT_EVER
each do |object|
result = yield object
max_object, max_result = object, result if max_result < result
end
max_object
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/min_by.rb 0000664 0000000 0000000 00000000663 12557303652 0022665 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :min_by
require 'backports/tools/extreme_object'
require 'enumerator'
module Enumerable
def min_by
return to_enum(:min_by) unless block_given?
min_object, min_result = nil, Backports::MOST_EXTREME_OBJECT_EVER
each do |object|
result = yield object
min_object, min_result = object, result if min_result > result
end
min_object
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/minmax.rb 0000664 0000000 0000000 00000001101 12557303652 0022665 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :minmax
require 'backports/tools/arguments'
module Enumerable
def minmax
return minmax{|a,b| a <=> b} unless block_given?
first_time = true
min, max = nil
each do |object|
if first_time
min = max = object
first_time = false
else
min = object if Backports.coerce_to_comparison(min, object, yield(min, object)) > 0
max = object if Backports.coerce_to_comparison(max, object, yield(max, object)) < 0
end
end
[min, max]
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/minmax_by.rb 0000664 0000000 0000000 00000001311 12557303652 0023362 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :minmax_by
require 'backports/tools/extreme_object'
require 'enumerator'
module Enumerable
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
def minmax_by
return to_enum(:minmax_by) unless block_given?
min_object, min_result = nil, Backports::MOST_EXTREME_OBJECT_EVER
max_object, max_result = nil, Backports::MOST_EXTREME_OBJECT_EVER
each do |object|
result = yield object
min_object, min_result = object, result if min_result > result
max_object, max_result = object, result if max_result < result
end
[min_object, max_object]
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/none.rb 0000664 0000000 0000000 00000000171 12557303652 0022341 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :none?
module Enumerable
def none?(&block)
!any?(&block)
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/one.rb 0000664 0000000 0000000 00000000665 12557303652 0022173 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :one?
module Enumerable
def one?
found_one = false
if block_given?
each do |o|
if yield(o)
return false if found_one
found_one = true
end
end
else
each do |o|
if o
return false if found_one
found_one = true
end
end
end
found_one
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/partition.rb 0000664 0000000 0000000 00000000166 12557303652 0023417 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Enumerable, :partition, :test_on => 1..2
backports-3.6.6/lib/backports/1.8.7/enumerable/reduce.rb 0000664 0000000 0000000 00000000054 12557303652 0022651 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/enumerable/inject'
backports-3.6.6/lib/backports/1.8.7/enumerable/reject.rb 0000664 0000000 0000000 00000000163 12557303652 0022657 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Enumerable, :reject, :test_on => 1..2
backports-3.6.6/lib/backports/1.8.7/enumerable/reverse_each.rb 0000664 0000000 0000000 00000000500 12557303652 0024031 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :reverse_each
require 'enumerator'
module Enumerable
def reverse_each
return to_enum(:reverse_each) unless block_given?
# There is no other way then to convert to an array first... see 1.9's source.
to_a.reverse_each{|e| yield e}
self
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/select.rb 0000664 0000000 0000000 00000000163 12557303652 0022662 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Enumerable, :select, :test_on => 1..2
backports-3.6.6/lib/backports/1.8.7/enumerable/sort_by.rb 0000664 0000000 0000000 00000000164 12557303652 0023065 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Enumerable, :sort_by, :test_on => 1..2
backports-3.6.6/lib/backports/1.8.7/enumerable/take.rb 0000664 0000000 0000000 00000000233 12557303652 0022325 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :take
require 'backports/1.8.7/enumerable/first'
module Enumerable
def take(n)
first(n)
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/take_while.rb 0000664 0000000 0000000 00000000616 12557303652 0023522 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :take_while
require 'enumerator'
module Enumerable
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
def take_while
return to_enum(:take_while) unless block_given?
inject([]) do |array, elem|
return array unless yield elem
array << elem
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerable/to_a.rb 0000664 0000000 0000000 00000000551 12557303652 0022326 0 ustar 00root root 0000000 0000000 if Enumerable.instance_method(:to_a).arity.zero?
require 'backports/tools/alias_method_chain'
require 'enumerator'
module Enumerable
def to_a_with_optional_arguments(*args)
return to_a_without_optional_arguments if args.empty?
to_enum(:each, *args).to_a
end
Backports.alias_method_chain self, :to_a, :optional_arguments
end
end
backports-3.6.6/lib/backports/1.8.7/enumerator.rb 0000664 0000000 0000000 00000000117 12557303652 0021444 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/enumerator/ 0000775 0000000 0000000 00000000000 12557303652 0021120 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/enumerator/each.rb 0000664 0000000 0000000 00000000315 12557303652 0022344 0 ustar 00root root 0000000 0000000 unless Object.const_defined? :Enumerator
require 'backports/tools/make_block_optional'
require 'enumerator'
Backports.make_block_optional Enumerable::Enumerator, :each, :test_on => [42].to_enum
end
backports-3.6.6/lib/backports/1.8.7/enumerator/next.rb 0000664 0000000 0000000 00000000607 12557303652 0022426 0 ustar 00root root 0000000 0000000 unless Object.const_defined? :Enumerator
require 'enumerator'
unless Enumerable::Enumerator.method_defined? :next
class Enumerable::Enumerator
require 'backports/1.8.7/stop_iteration'
def next
require 'generator'
@generator ||= ::Generator.new(self)
raise StopIteration unless @generator.next?
@generator.next
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerator/rewind.rb 0000664 0000000 0000000 00000000466 12557303652 0022743 0 ustar 00root root 0000000 0000000 unless Object.const_defined? :Enumerator
require 'enumerator'
unless Enumerable::Enumerator.method_defined? :rewind
class Enumerable::Enumerator
def rewind
require 'generator'
@generator ||= ::Generator.new(self)
@generator.rewind
self
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/enumerator/with_index.rb 0000664 0000000 0000000 00000000614 12557303652 0023610 0 ustar 00root root 0000000 0000000 unless Object.const_defined? :Enumerator
require 'enumerator'
unless Enumerable::Enumerator.method_defined? :with_index
class Enumerable::Enumerator
def with_index(offset = 0)
return to_enum(:with_index, offset) unless block_given?
each do |*args|
yield args.size == 1 ? args[0] : args, offset
offset += 1
end
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/env.rb 0000664 0000000 0000000 00000000117 12557303652 0020053 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/env/ 0000775 0000000 0000000 00000000000 12557303652 0017527 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/env/delete_if.rb 0000664 0000000 0000000 00000000156 12557303652 0021776 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional ENV, :delete_if, :test_on => ENV
backports-3.6.6/lib/backports/1.8.7/env/each.rb 0000664 0000000 0000000 00000000151 12557303652 0020751 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional ENV, :each, :test_on => ENV
backports-3.6.6/lib/backports/1.8.7/env/each_key.rb 0000664 0000000 0000000 00000000155 12557303652 0021625 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional ENV, :each_key, :test_on => ENV
backports-3.6.6/lib/backports/1.8.7/env/each_pair.rb 0000664 0000000 0000000 00000000156 12557303652 0021771 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional ENV, :each_pair, :test_on => ENV
backports-3.6.6/lib/backports/1.8.7/env/each_value.rb 0000664 0000000 0000000 00000000157 12557303652 0022153 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional ENV, :each_value, :test_on => ENV
backports-3.6.6/lib/backports/1.8.7/env/reject.rb 0000664 0000000 0000000 00000000250 12557303652 0021325 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional ENV, :reject, :test_on => ENV
Backports.make_block_optional ENV, :reject!, :test_on => ENV
backports-3.6.6/lib/backports/1.8.7/env/select.rb 0000664 0000000 0000000 00000000153 12557303652 0021332 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional ENV, :select, :test_on => ENV
backports-3.6.6/lib/backports/1.8.7/fixnum.rb 0000664 0000000 0000000 00000000117 12557303652 0020571 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/fixnum/ 0000775 0000000 0000000 00000000000 12557303652 0020245 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/fixnum/div.rb 0000664 0000000 0000000 00000000151 12557303652 0021351 0 ustar 00root root 0000000 0000000 unless Fixnum.method_defined? :div
class Fixnum
def div(n)
(self / n).to_i
end
end
end
backports-3.6.6/lib/backports/1.8.7/fixnum/fdiv.rb 0000664 0000000 0000000 00000000144 12557303652 0021521 0 ustar 00root root 0000000 0000000 unless Fixnum.method_defined? :fdiv
class Fixnum
def fdiv(n)
to_f / n
end
end
end
backports-3.6.6/lib/backports/1.8.7/float.rb 0000664 0000000 0000000 00000000117 12557303652 0020370 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/float/ 0000775 0000000 0000000 00000000000 12557303652 0020044 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/float/fdiv.rb 0000664 0000000 0000000 00000000115 12557303652 0021316 0 ustar 00root root 0000000 0000000 unless Float.method_defined? :fdiv
Float.send :alias_method, :fdiv, :/
end
backports-3.6.6/lib/backports/1.8.7/gc.rb 0000664 0000000 0000000 00000000117 12557303652 0017654 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/gc/ 0000775 0000000 0000000 00000000000 12557303652 0017330 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/gc/stress.rb 0000664 0000000 0000000 00000000176 12557303652 0021204 0 ustar 00root root 0000000 0000000 unless GC.respond_to? :stress
def GC.stress
false
end
def GC.stress=(flag)
raise NotImplementedError
end
end
backports-3.6.6/lib/backports/1.8.7/hash.rb 0000664 0000000 0000000 00000000117 12557303652 0020206 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/hash/ 0000775 0000000 0000000 00000000000 12557303652 0017662 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/hash/constructor.rb 0000664 0000000 0000000 00000001275 12557303652 0022601 0 ustar 00root root 0000000 0000000 unless (Hash[[[:test, :test]]] rescue false)
require 'backports/tools/arguments'
class << Hash
alias_method :constructor_without_key_value_pair_form, :[]
def [](*args)
if args.length == 1
arg = args.first
if (h = Backports.try_convert(arg, Hash, :to_hash))
return allocate.replace(h)
end
if (kvps = Backports.is_array?(arg))
h = {}
kvps.each do |elem|
next unless arr = Backports.is_array?(elem)
next unless (1..2).include? arr.size
h[arr.at(0)] = arr.at(1)
end
return h
end
end
constructor_without_key_value_pair_form(*args)
end
end
end
backports-3.6.6/lib/backports/1.8.7/hash/delete_if.rb 0000664 0000000 0000000 00000000200 12557303652 0022117 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Hash, :delete_if, :test_on => {:hello => "world!"}
backports-3.6.6/lib/backports/1.8.7/hash/each.rb 0000664 0000000 0000000 00000000173 12557303652 0021110 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Hash, :each, :test_on => {:hello => "world!"}
backports-3.6.6/lib/backports/1.8.7/hash/each_key.rb 0000664 0000000 0000000 00000000177 12557303652 0021764 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Hash, :each_key, :test_on => {:hello => "world!"}
backports-3.6.6/lib/backports/1.8.7/hash/each_pair.rb 0000664 0000000 0000000 00000000200 12557303652 0022112 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Hash, :each_pair, :test_on => {:hello => "world!"}
backports-3.6.6/lib/backports/1.8.7/hash/each_value.rb 0000664 0000000 0000000 00000000201 12557303652 0022274 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Hash, :each_value, :test_on => {:hello => "world!"}
backports-3.6.6/lib/backports/1.8.7/hash/eql.rb 0000664 0000000 0000000 00000000044 12557303652 0020766 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/hash/hash'
backports-3.6.6/lib/backports/1.8.7/hash/hash.rb 0000664 0000000 0000000 00000000505 12557303652 0021132 0 ustar 00root root 0000000 0000000 class Hash
def hash
h = 0
each do |key, value|
h ^= key.hash ^ value.hash
end
h
end unless {}.hash == {}.hash
def eql?(other)
other.is_a?(Hash) &&
size == other.size &&
all? do |key, value|
value.eql?(other.fetch(key){return false})
end
end unless {}.eql?({})
end
backports-3.6.6/lib/backports/1.8.7/hash/reject.rb 0000664 0000000 0000000 00000000207 12557303652 0021462 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Hash, :reject, :reject!, :test_on => {:hello => "world!"}
backports-3.6.6/lib/backports/1.8.7/hash/select.rb 0000664 0000000 0000000 00000000175 12557303652 0021471 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Hash, :select, :test_on => {:hello => "world!"}
backports-3.6.6/lib/backports/1.8.7/integer.rb 0000664 0000000 0000000 00000000117 12557303652 0020720 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/integer/ 0000775 0000000 0000000 00000000000 12557303652 0020374 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/integer/downto.rb 0000664 0000000 0000000 00000000172 12557303652 0022233 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Integer, :downto, :test_on => 42, :arg => 42
backports-3.6.6/lib/backports/1.8.7/integer/even.rb 0000664 0000000 0000000 00000000152 12557303652 0021654 0 ustar 00root root 0000000 0000000 unless Integer.method_defined? :even?
class Integer
def even?
self[0].zero?
end
end
end
backports-3.6.6/lib/backports/1.8.7/integer/odd.rb 0000664 0000000 0000000 00000000151 12557303652 0021464 0 ustar 00root root 0000000 0000000 unless Integer.method_defined? :odd?
class Integer
def odd?
!self[0].zero?
end
end
end
backports-3.6.6/lib/backports/1.8.7/integer/ord.rb 0000664 0000000 0000000 00000000135 12557303652 0021504 0 ustar 00root root 0000000 0000000 unless Integer.method_defined? :ord
class Integer
def ord
self
end
end
end
backports-3.6.6/lib/backports/1.8.7/integer/pred.rb 0000664 0000000 0000000 00000000143 12557303652 0021651 0 ustar 00root root 0000000 0000000 unless Integer.method_defined? :pred
class Integer
def pred
self - 1
end
end
end
backports-3.6.6/lib/backports/1.8.7/integer/times.rb 0000664 0000000 0000000 00000000155 12557303652 0022043 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Integer, :times, :test_on => 42
backports-3.6.6/lib/backports/1.8.7/integer/upto.rb 0000664 0000000 0000000 00000000170 12557303652 0021706 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Integer, :upto, :test_on => 42, :arg => 42
backports-3.6.6/lib/backports/1.8.7/io.rb 0000664 0000000 0000000 00000000117 12557303652 0017672 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/io/ 0000775 0000000 0000000 00000000000 12557303652 0017346 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/io/bytes.rb 0000664 0000000 0000000 00000000047 12557303652 0021022 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/io/each_byte'
backports-3.6.6/lib/backports/1.8.7/io/chars.rb 0000664 0000000 0000000 00000000047 12557303652 0020774 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/io/each_char'
backports-3.6.6/lib/backports/1.8.7/io/each.rb 0000664 0000000 0000000 00000000201 12557303652 0020564 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional IO, :each, :force => true if RUBY_VERSION < '1.8.7'
backports-3.6.6/lib/backports/1.8.7/io/each_byte.rb 0000664 0000000 0000000 00000000270 12557303652 0021615 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
if RUBY_VERSION < '1.8.7'
Backports.make_block_optional IO, :each_byte, :force => true
IO.send :alias_method, :bytes, :each_byte
end
backports-3.6.6/lib/backports/1.8.7/io/each_char.rb 0000664 0000000 0000000 00000001371 12557303652 0021572 0 ustar 00root root 0000000 0000000 unless IO.method_defined? :each_char
require 'enumerator'
class IO
def each_char
return to_enum(:each_char) unless block_given?
if $KCODE == "UTF-8"
lookup = 7.downto(4)
while c = read(1) do
n = c[0]
leftmost_zero_bit = lookup.find{|i| n[i].zero? }
case leftmost_zero_bit
when 7 # ASCII
yield c
when 6 # UTF 8 complementary characters
next # Encoding error, ignore
else
more = read(6-leftmost_zero_bit)
break unless more
yield c+more
end
end
else
while s = read(1)
yield s
end
end
self
end
alias_method :chars, :each_char
end
end
backports-3.6.6/lib/backports/1.8.7/io/each_line.rb 0000664 0000000 0000000 00000000270 12557303652 0021601 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
if RUBY_VERSION < '1.8.7'
Backports.make_block_optional IO, :each_line, :force => true
IO.send :alias_method, :lines, :each_line
end
backports-3.6.6/lib/backports/1.8.7/io/foreach.rb 0000664 0000000 0000000 00000000244 12557303652 0021302 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.8.7'
require 'backports/tools/make_block_optional'
class << IO
Backports.make_block_optional self, :foreach, :force => true
end
end
backports-3.6.6/lib/backports/1.8.7/io/getbyte.rb 0000664 0000000 0000000 00000000123 12557303652 0021332 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method IO, :getbyte, :getc
backports-3.6.6/lib/backports/1.8.7/io/lines.rb 0000664 0000000 0000000 00000000047 12557303652 0021006 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/io/each_line'
backports-3.6.6/lib/backports/1.8.7/io/readbyte.rb 0000664 0000000 0000000 00000000130 12557303652 0021464 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method IO, :readbyte, :readchar
backports-3.6.6/lib/backports/1.8.7/kernel.rb 0000664 0000000 0000000 00000000117 12557303652 0020543 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/kernel/ 0000775 0000000 0000000 00000000000 12557303652 0020217 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/kernel/__method__.rb 0000664 0000000 0000000 00000000230 12557303652 0022613 0 ustar 00root root 0000000 0000000 unless (__method__ || true rescue false)
module Kernel
def __method__
m = caller(1).first[/`(.*)'/,1]
m.to_sym if m
end
end
end
backports-3.6.6/lib/backports/1.8.7/kernel/instance_exec.rb 0000664 0000000 0000000 00000000433 12557303652 0023354 0 ustar 00root root 0000000 0000000 unless Object.method_defined?(:instance_exec)
module Kernel
def instance_exec(*arg, &block)
class << self
self
end.send(:define_method, :"temporary method for instance_exec", &block)
send(:"temporary method for instance_exec", *arg)
end
end
end
backports-3.6.6/lib/backports/1.8.7/kernel/tap.rb 0000664 0000000 0000000 00000000155 12557303652 0021331 0 ustar 00root root 0000000 0000000 unless Kernel.method_defined? :tap
module Kernel
def tap
yield self
self
end
end
end
backports-3.6.6/lib/backports/1.8.7/method.rb 0000664 0000000 0000000 00000000117 12557303652 0020543 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/method/ 0000775 0000000 0000000 00000000000 12557303652 0020217 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/method/name.rb 0000664 0000000 0000000 00000002566 12557303652 0021475 0 ustar 00root root 0000000 0000000 unless Method.method_defined? :name
require 'backports/tools/alias_method_chain'
class Method
attr_accessor :name, :receiver, :owner
def unbind_with_additional_info
unbound = unbind_without_additional_info
unbound.name = name
unbound.owner = owner
unbound
end
Backports.alias_method_chain self, :unbind, :additional_info
end
class UnboundMethod
attr_accessor :name, :owner
def bind_with_additional_info(to)
bound = bind_without_additional_info(to)
bound.name = name
bound.owner = owner
bound.receiver = to
bound
end
Backports.alias_method_chain self, :bind, :additional_info
end
module Kernel
def method_with_additional_info(name)
bound = method_without_additional_info(name)
bound.name = name.to_s
bound.receiver = self
bound.owner = self.class.ancestors.find{|mod| mod.instance_methods(false).include? bound.name}
bound
end
Backports.alias_method_chain self, :method, :additional_info
end
class Module
def instance_method_with_additional_info(name)
unbound = instance_method_without_additional_info(name)
unbound.name = name.to_s
unbound.owner = ancestors.find{|mod| mod.instance_methods(false).include? unbound.name}
unbound
end
Backports.alias_method_chain self, :instance_method, :additional_info
end
end
backports-3.6.6/lib/backports/1.8.7/module.rb 0000664 0000000 0000000 00000000117 12557303652 0020550 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/module/ 0000775 0000000 0000000 00000000000 12557303652 0020224 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/module/class_exec.rb 0000664 0000000 0000000 00000000055 12557303652 0022662 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/module/module_exec'
backports-3.6.6/lib/backports/1.8.7/module/module_exec.rb 0000664 0000000 0000000 00000000446 12557303652 0023046 0 ustar 00root root 0000000 0000000 unless Module.method_defined? :module_exec
require 'backports/tools/alias_method'
require 'backports/1.8.7/kernel/instance_exec'
class Module
def module_exec(*arg, &block)
instance_exec(*arg, &block)
end
end
Backports.alias_method Module, :class_exec, :module_exec
end
backports-3.6.6/lib/backports/1.8.7/numeric.rb 0000664 0000000 0000000 00000000117 12557303652 0020725 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/numeric/ 0000775 0000000 0000000 00000000000 12557303652 0020401 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/numeric/step.rb 0000664 0000000 0000000 00000000176 12557303652 0021705 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Numeric, :step, :test_on => 42, :arg => [100, 6]
backports-3.6.6/lib/backports/1.8.7/object_space.rb 0000664 0000000 0000000 00000000117 12557303652 0021704 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/object_space/ 0000775 0000000 0000000 00000000000 12557303652 0021360 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/object_space/each_object.rb 0000664 0000000 0000000 00000000224 12557303652 0024131 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
class << ObjectSpace
Backports.make_block_optional self, :each_object, :test_on => ObjectSpace
end
backports-3.6.6/lib/backports/1.8.7/process.rb 0000664 0000000 0000000 00000000117 12557303652 0020741 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/process/ 0000775 0000000 0000000 00000000000 12557303652 0020415 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/process/exec.rb 0000664 0000000 0000000 00000000044 12557303652 0021664 0 ustar 00root root 0000000 0000000 class << Process
public :exec
end
backports-3.6.6/lib/backports/1.8.7/range.rb 0000664 0000000 0000000 00000000117 12557303652 0020357 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/range/ 0000775 0000000 0000000 00000000000 12557303652 0020033 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/range/each.rb 0000664 0000000 0000000 00000000157 12557303652 0021263 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Range, :each, :test_on => 69..666
backports-3.6.6/lib/backports/1.8.7/range/step.rb 0000664 0000000 0000000 00000000173 12557303652 0021334 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Range, :step, :test_on => 69..666, :arg => 42
backports-3.6.6/lib/backports/1.8.7/regexp.rb 0000664 0000000 0000000 00000000117 12557303652 0020555 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/regexp/ 0000775 0000000 0000000 00000000000 12557303652 0020231 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/regexp/union.rb 0000664 0000000 0000000 00000000533 12557303652 0021707 0 ustar 00root root 0000000 0000000 unless (Regexp.union(%w(a b)) rescue false)
require 'backports/tools/alias_method_chain'
class << Regexp
def union_with_array_argument(*arg)
return union_without_array_argument(*arg) unless arg.size == 1
union_without_array_argument(*arg.first)
end
Backports.alias_method_chain self, :union, :array_argument
end
end
backports-3.6.6/lib/backports/1.8.7/stdlib.rb 0000664 0000000 0000000 00000000042 12557303652 0020541 0 ustar 00root root 0000000 0000000 Backports::StdLib.extend_relative
backports-3.6.6/lib/backports/1.8.7/stdlib/ 0000775 0000000 0000000 00000000000 12557303652 0020220 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/stdlib/tmpdir.rb 0000664 0000000 0000000 00000002072 12557303652 0022045 0 ustar 00root root 0000000 0000000 unless Dir.respond_to? :mktmpdir
class << Dir
def mktmpdir(prefix_suffix=nil, tmpdir=nil)
raise NoMethodError, "undefined method `mktmpdir' for Dir:Class; you must require 'tmpdir'" unless respond_to? :tmpdir
case prefix_suffix
when nil
prefix = "d"
suffix = ""
when String
prefix = prefix_suffix
suffix = ""
when Array
prefix = prefix_suffix[0]
suffix = prefix_suffix[1]
else
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
end
tmpdir ||= Dir.tmpdir
t = Time.now.strftime("%Y%m%d")
n = nil
begin
path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{Kernel.rand(0x100000000).to_s(36)}"
path << "-#{n}" if n
path << suffix
Dir.mkdir(path, 0700)
rescue Errno::EEXIST
n ||= 0
n += 1
retry
end
if block_given?
begin
yield path
ensure
FileUtils.remove_entry_secure path
end
else
path
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/stop_iteration.rb 0000664 0000000 0000000 00000000551 12557303652 0022330 0 ustar 00root root 0000000 0000000 unless Object.const_defined? :StopIteration
require 'backports/tools/alias_method_chain'
class StopIteration < IndexError; end
module Kernel
def loop_with_stop_iteration(&block)
loop_without_stop_iteration(&block)
rescue StopIteration
# ignore silently
end
Backports.alias_method_chain self, :loop, :stop_iteration
end
end
backports-3.6.6/lib/backports/1.8.7/string.rb 0000664 0000000 0000000 00000000117 12557303652 0020571 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/string/ 0000775 0000000 0000000 00000000000 12557303652 0020245 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/string/bytes.rb 0000664 0000000 0000000 00000000053 12557303652 0021716 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/string/each_byte'
backports-3.6.6/lib/backports/1.8.7/string/bytesize.rb 0000664 0000000 0000000 00000000132 12557303652 0022424 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method String, :bytesize, :length
backports-3.6.6/lib/backports/1.8.7/string/each.rb 0000664 0000000 0000000 00000000235 12557303652 0021472 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional String, :each, :test_on => "abc" if "is there still an each?".respond_to? :each
backports-3.6.6/lib/backports/1.8.7/string/each_byte.rb 0000664 0000000 0000000 00000000246 12557303652 0022517 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional String, :each_byte, :test_on => "abc"
Backports.alias_method String, :bytes, :each_byte
backports-3.6.6/lib/backports/1.8.7/string/each_char.rb 0000664 0000000 0000000 00000000446 12557303652 0022473 0 ustar 00root root 0000000 0000000 unless String.method_defined? :each_char
require 'backports/tools/alias_method'
require 'enumerator'
class String
def each_char
return to_enum(:each_char) unless block_given?
scan(/./m) {|c| yield c}
end
Backports.alias_method self, :chars, :each_char
end
end
backports-3.6.6/lib/backports/1.8.7/string/each_line.rb 0000664 0000000 0000000 00000000246 12557303652 0022503 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional String, :each_line, :test_on => "abc"
Backports.alias_method String, :lines, :each_line
backports-3.6.6/lib/backports/1.8.7/string/end_with.rb 0000664 0000000 0000000 00000000434 12557303652 0022374 0 ustar 00root root 0000000 0000000 unless String.method_defined? :end_with?
class String
def end_with?(*suffixes)
suffixes.any? do |suffix|
if suffix.respond_to? :to_str
suffix = suffix.to_str
self[-suffix.length, suffix.length] == suffix
end
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/string/lines.rb 0000664 0000000 0000000 00000000053 12557303652 0021702 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/string/each_line'
backports-3.6.6/lib/backports/1.8.7/string/partition.rb 0000664 0000000 0000000 00000001412 12557303652 0022601 0 ustar 00root root 0000000 0000000 unless ("check partition".partition(" ") rescue false)
require 'backports/tools/alias_method_chain'
require 'backports/tools/arguments'
class String
def partition_with_new_meaning(pattern = Backports::Undefined)
return partition_without_new_meaning{|c| yield c} if pattern == Backports::Undefined
pattern = Backports.coerce_to(pattern, String, :to_str) unless pattern.is_a? Regexp
i = index(pattern)
return [self, "", ""] unless i
if pattern.is_a? Regexp
match = Regexp.last_match
[match.pre_match, match[0], match.post_match]
else
last = i+pattern.length
[self[0...i], self[i...last], self[last...length]]
end
end
Backports.alias_method_chain self, :partition, :new_meaning
end
end
backports-3.6.6/lib/backports/1.8.7/string/rpartition.rb 0000664 0000000 0000000 00000001016 12557303652 0022763 0 ustar 00root root 0000000 0000000 unless String.method_defined? :rpartition
require 'backports/tools/arguments'
class String
def rpartition(pattern)
pattern = Backports.coerce_to(pattern, String, :to_str) unless pattern.is_a? Regexp
i = rindex(pattern)
return ["", "", self] unless i
if pattern.is_a? Regexp
match = Regexp.last_match
[match.pre_match, match[0], match.post_match]
else
last = i+pattern.length
[self[0...i], self[i...last], self[last...length]]
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/string/start_with.rb 0000664 0000000 0000000 00000000423 12557303652 0022761 0 ustar 00root root 0000000 0000000 unless String.method_defined? :start_with?
class String
def start_with?(*prefixes)
prefixes.any? do |prefix|
if prefix.respond_to? :to_str
prefix = prefix.to_str
self[0, prefix.length] == prefix
end
end
end
end
end
backports-3.6.6/lib/backports/1.8.7/string/upto.rb 0000664 0000000 0000000 00000000677 12557303652 0021573 0 ustar 00root root 0000000 0000000 unless ("abc".upto("def", true){} rescue false)
require 'backports/tools/alias_method_chain'
require 'enumerator'
class String
def upto_with_exclusive(to, excl=false)
return upto_without_exclusive(to){|s| yield s} if block_given? && !excl
r = Range.new(self, to, excl)
return r.to_enum unless block_given?
r.each{|s| yield s}
self
end
Backports.alias_method_chain self, :upto, :exclusive
end
end
backports-3.6.6/lib/backports/1.8.7/struct.rb 0000664 0000000 0000000 00000000117 12557303652 0020607 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/struct/ 0000775 0000000 0000000 00000000000 12557303652 0020263 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/struct/each.rb 0000664 0000000 0000000 00000000203 12557303652 0021503 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Struct, :each, :test_on => Struct.new(:foo, :bar).new
backports-3.6.6/lib/backports/1.8.7/struct/each_pair.rb 0000664 0000000 0000000 00000000210 12557303652 0022514 0 ustar 00root root 0000000 0000000 require 'backports/tools/make_block_optional'
Backports.make_block_optional Struct, :each_pair, :test_on => Struct.new(:foo, :bar).new
backports-3.6.6/lib/backports/1.8.7/symbol.rb 0000664 0000000 0000000 00000000117 12557303652 0020570 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.8.7/symbol/ 0000775 0000000 0000000 00000000000 12557303652 0020244 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.8.7/symbol/to_proc.rb 0000664 0000000 0000000 00000000400 12557303652 0022230 0 ustar 00root root 0000000 0000000 unless Symbol.method_defined? :to_proc
class Symbol
# Standard in ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Symbol.html]
def to_proc
Proc.new { |*args| args.shift.__send__(self, *args) }
end
end
end
backports-3.6.6/lib/backports/1.8.8.rb 0000664 0000000 0000000 00000000272 12557303652 0017266 0 ustar 00root root 0000000 0000000 # Ruby 1.8.8 has been officially cancelled. As of version 2.2 of backports, require "backports/1.8.8"
# does nothing more than require 1.8.7 backports
require 'backports/1.8.7'
backports-3.6.6/lib/backports/1.8.rb 0000664 0000000 0000000 00000000137 12557303652 0017120 0 ustar 00root root 0000000 0000000 # require this file to load all the backports of the Ruby 1.8.x line
require 'backports/1.8.7'
backports-3.6.6/lib/backports/1.9.1.rb 0000664 0000000 0000000 00000000231 12557303652 0017253 0 ustar 00root root 0000000 0000000 # require this file to load all the backports up to Ruby 1.9.1 (including all of 1.8.8 and below)
require 'backports/1.8'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/ 0000775 0000000 0000000 00000000000 12557303652 0016732 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/array.rb 0000664 0000000 0000000 00000000117 12557303652 0020374 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/array/ 0000775 0000000 0000000 00000000000 12557303652 0020050 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/array/sample.rb 0000664 0000000 0000000 00000002063 12557303652 0021657 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :sample
require 'backports/tools/arguments'
class Array
def sample(n = Backports::Undefined, options = Backports::Undefined)
if options == Backports::Undefined && n.respond_to?(:to_hash)
n, options = options, n
end
rng = Backports.coerce_to_option(options, :random) unless options == Backports::Undefined
generator = if rng.respond_to? :rand
Proc.new do |nb|
r = Backports::coerce_to_int(rng.rand(nb))
raise RangeError, "random generator returned #{r} which is not in 0...#{nb}" if r < 0 || r >= nb
r
end
else
Kernel.method(:rand)
end
return self[generator.call(size)] if n == Backports::Undefined
n = Backports.coerce_to_int(n)
raise ArgumentError, "negative array size" if n < 0
n = size if n > size
result = Array.new(self)
n.times do |i|
r = i + generator.call(size - i)
result[i], result[r] = result[r], result[i]
end
result[n..size] = []
result
end
end
end
backports-3.6.6/lib/backports/1.9.1/array/try_convert.rb 0000664 0000000 0000000 00000000243 12557303652 0022752 0 ustar 00root root 0000000 0000000 unless Array.respond_to? :try_convert
require 'backports/tools/arguments'
def Array.try_convert(obj)
Backports.try_convert(obj, Array, :to_ary)
end
end
backports-3.6.6/lib/backports/1.9.1/dir.rb 0000664 0000000 0000000 00000000117 12557303652 0020034 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/dir/ 0000775 0000000 0000000 00000000000 12557303652 0017510 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/dir/to_path.rb 0000664 0000000 0000000 00000000124 12557303652 0021470 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method Dir, :to_path, :path
backports-3.6.6/lib/backports/1.9.1/enumerable.rb 0000664 0000000 0000000 00000000117 12557303652 0021375 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/enumerable/ 0000775 0000000 0000000 00000000000 12557303652 0021051 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/enumerable/each_with_index.rb 0000664 0000000 0000000 00000000704 12557303652 0024521 0 ustar 00root root 0000000 0000000 if Enumerable.instance_method(:each_with_index).arity.zero?
require 'backports/tools/alias_method_chain'
require 'enumerator'
module Enumerable
def each_with_index_with_optional_args_and_block(*args)
return to_enum(:each_with_index, *args) unless block_given?
idx = 0
each(*args) { |o| yield(o, idx); idx += 1 }
self
end
Backports.alias_method_chain self, :each_with_index, :optional_args_and_block
end
end
backports-3.6.6/lib/backports/1.9.1/enumerable/each_with_object.rb 0000664 0000000 0000000 00000000351 12557303652 0024656 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :each_with_object
module Enumerable
def each_with_object(memo)
return to_enum(:each_with_object, memo) unless block_given?
each {|obj| yield obj, memo}
memo
end
end
end
backports-3.6.6/lib/backports/1.9.1/enumerator.rb 0000664 0000000 0000000 00000000117 12557303652 0021437 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/enumerator/ 0000775 0000000 0000000 00000000000 12557303652 0021113 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/enumerator/new.rb 0000664 0000000 0000000 00000002160 12557303652 0022230 0 ustar 00root root 0000000 0000000 Enumerator = Enumerable::Enumerator unless Object.const_defined? :Enumerator # Standard in ruby 1.9
unless (Enumerator.new{} rescue false)
require 'backports/tools/alias_method_chain'
# new with block, standard in Ruby 1.9
class Enumerator
# A simple class which allows the construction of Enumerator from a block
class Yielder
def initialize(&block)
@final_block = block
end
def yield(*arg)
@final_block.call(*arg)
end
def <<(*arg)
@final_block.call(*arg)
self
end
end
class GeneratorBP # Avoid conflict with 1.8's ::Generator class
def initialize(&block)
@main_block = block
end
def each(&block)
@main_block.call(Yielder.new(&block))
end
end
def initialize_with_optional_block(*arg, &block)
return initialize_without_optional_block(*arg, &nil) unless arg.empty? # Ruby 1.9 apparently ignores the block if any argument is present
initialize_without_optional_block(GeneratorBP.new(&block))
end
Backports.alias_method_chain self, :initialize, :optional_block
end
end
backports-3.6.6/lib/backports/1.9.1/enumerator/with_object.rb 0000664 0000000 0000000 00000000406 12557303652 0023741 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
require 'backports/1.9.1/enumerable/each_with_object'
Enumerator = Enumerable::Enumerator unless Object.const_defined? :Enumerator # Standard in ruby 1.9
Backports.alias_method Enumerator, :with_object, :each_with_object
backports-3.6.6/lib/backports/1.9.1/env.rb 0000664 0000000 0000000 00000000117 12557303652 0020046 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/env/ 0000775 0000000 0000000 00000000000 12557303652 0017522 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/env/key.rb 0000664 0000000 0000000 00000000145 12557303652 0020637 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
class << ENV
Backports.alias_method self, :key, :index
end
backports-3.6.6/lib/backports/1.9.1/file.rb 0000664 0000000 0000000 00000000117 12557303652 0020175 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/file/ 0000775 0000000 0000000 00000000000 12557303652 0017651 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/file/atime.rb 0000664 0000000 0000000 00000000166 12557303652 0021300 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :atime
end
backports-3.6.6/lib/backports/1.9.1/file/basename.rb 0000664 0000000 0000000 00000000171 12557303652 0021750 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :basename
end
backports-3.6.6/lib/backports/1.9.1/file/binary.rb 0000664 0000000 0000000 00000000207 12557303652 0021461 0 ustar 00root root 0000000 0000000 class File
module Constants
# In Ruby 1.8, it is defined only on Windows
BINARY = 0 unless const_defined?(:BINARY)
end
end
backports-3.6.6/lib/backports/1.9.1/file/blockdev.rb 0000664 0000000 0000000 00000000172 12557303652 0021767 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :blockdev?
end
backports-3.6.6/lib/backports/1.9.1/file/chardev.rb 0000664 0000000 0000000 00000000171 12557303652 0021611 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :chardev?
end
backports-3.6.6/lib/backports/1.9.1/file/chmod.rb 0000664 0000000 0000000 00000000170 12557303652 0021266 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_all_arguments_to_path File, :chmod, 1
end
backports-3.6.6/lib/backports/1.9.1/file/chown.rb 0000664 0000000 0000000 00000000170 12557303652 0021312 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_all_arguments_to_path File, :chown, 2
end
backports-3.6.6/lib/backports/1.9.1/file/ctime.rb 0000664 0000000 0000000 00000000166 12557303652 0021302 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :ctime
end
backports-3.6.6/lib/backports/1.9.1/file/delete.rb 0000664 0000000 0000000 00000000171 12557303652 0021437 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_all_arguments_to_path File, :delete, 0
end
backports-3.6.6/lib/backports/1.9.1/file/directory.rb 0000664 0000000 0000000 00000000173 12557303652 0022203 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :directory?
end
backports-3.6.6/lib/backports/1.9.1/file/dirname.rb 0000664 0000000 0000000 00000000170 12557303652 0021613 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :dirname
end
backports-3.6.6/lib/backports/1.9.1/file/executable.rb 0000664 0000000 0000000 00000000174 12557303652 0022321 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :executable?
end
backports-3.6.6/lib/backports/1.9.1/file/executable_real.rb 0000664 0000000 0000000 00000000201 12557303652 0023313 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :executable_real?
end
backports-3.6.6/lib/backports/1.9.1/file/exist.rb 0000664 0000000 0000000 00000000167 12557303652 0021336 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :exist?
end
backports-3.6.6/lib/backports/1.9.1/file/exists.rb 0000664 0000000 0000000 00000000170 12557303652 0021513 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :exists?
end
backports-3.6.6/lib/backports/1.9.1/file/expand_path.rb 0000664 0000000 0000000 00000000700 12557303652 0022466 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
class << File
def expand_path_with_potential_to_path(file, dir = nil)
raise ArgumentError, 'home not set' if file == '~' && ENV["HOME"] == ''
expand_path_without_potential_to_path(
Backports.convert_path(file),
dir == nil ? dir : Backports.convert_path(dir)
)
end
Backports.alias_method_chain self, :expand_path, :potential_to_path
end
end
backports-3.6.6/lib/backports/1.9.1/file/extname.rb 0000664 0000000 0000000 00000000170 12557303652 0021635 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :extname
end
backports-3.6.6/lib/backports/1.9.1/file/file.rb 0000664 0000000 0000000 00000000166 12557303652 0021120 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :file?
end
backports-3.6.6/lib/backports/1.9.1/file/ftype.rb 0000664 0000000 0000000 00000000166 12557303652 0021330 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :ftype
end
backports-3.6.6/lib/backports/1.9.1/file/grpowned.rb 0000664 0000000 0000000 00000000172 12557303652 0022023 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :grpowned?
end
backports-3.6.6/lib/backports/1.9.1/file/join.rb 0000664 0000000 0000000 00000000167 12557303652 0021141 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_all_arguments_to_path File, :join, 0
end
backports-3.6.6/lib/backports/1.9.1/file/lchmod.rb 0000664 0000000 0000000 00000000226 12557303652 0021444 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9' && File.respond_to?(:lchmod)
require 'backports/tools/path'
Backports.convert_all_arguments_to_path File, :lchmod, 1
end
backports-3.6.6/lib/backports/1.9.1/file/lchown.rb 0000664 0000000 0000000 00000000171 12557303652 0021467 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_all_arguments_to_path File, :lchown, 2
end
backports-3.6.6/lib/backports/1.9.1/file/link.rb 0000664 0000000 0000000 00000000165 12557303652 0021135 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :link
end
backports-3.6.6/lib/backports/1.9.1/file/lstat.rb 0000664 0000000 0000000 00000000166 12557303652 0021330 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :lstat
end
backports-3.6.6/lib/backports/1.9.1/file/mtime.rb 0000664 0000000 0000000 00000000166 12557303652 0021314 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :mtime
end
backports-3.6.6/lib/backports/1.9.1/file/new.rb 0000664 0000000 0000000 00000000164 12557303652 0020770 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :new
end
backports-3.6.6/lib/backports/1.9.1/file/open.rb 0000664 0000000 0000000 00000001326 12557303652 0021141 0 ustar 00root root 0000000 0000000 begin
File.open(__FILE__, :mode => 'r'){}
rescue TypeError
require 'backports/tools/alias_method_chain'
require 'backports/tools/io'
def open_with_options_hash(file, mode = nil, perm_or_options = Backports::Undefined)
mode, perm = Backports.combine_mode_perm_and_option(mode, perm_or_options)
perm ||= 0666 # Avoid error on Rubinius, see issue #52
if block_given?
open_without_options_hash(file, mode, perm){|f| yield f}
else
open_without_options_hash(file, mode, perm)
end
end
class << File
Backports.alias_method_chain self, :open, :options_hash
end
end
if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :open
end
backports-3.6.6/lib/backports/1.9.1/file/owned.rb 0000664 0000000 0000000 00000000167 12557303652 0021316 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :owned?
end
backports-3.6.6/lib/backports/1.9.1/file/pipe.rb 0000664 0000000 0000000 00000000166 12557303652 0021136 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :pipe?
end
backports-3.6.6/lib/backports/1.9.1/file/readable.rb 0000664 0000000 0000000 00000000172 12557303652 0021735 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :readable?
end
backports-3.6.6/lib/backports/1.9.1/file/readable_real.rb 0000664 0000000 0000000 00000000177 12557303652 0022745 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :readable_real?
end
backports-3.6.6/lib/backports/1.9.1/file/readlink.rb 0000664 0000000 0000000 00000000171 12557303652 0021766 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :readlink
end
backports-3.6.6/lib/backports/1.9.1/file/rename.rb 0000664 0000000 0000000 00000000167 12557303652 0021451 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :rename
end
backports-3.6.6/lib/backports/1.9.1/file/setgid.rb 0000664 0000000 0000000 00000000170 12557303652 0021453 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :setgid?
end
backports-3.6.6/lib/backports/1.9.1/file/setuid.rb 0000664 0000000 0000000 00000000170 12557303652 0021471 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :setuid?
end
backports-3.6.6/lib/backports/1.9.1/file/size.rb 0000664 0000000 0000000 00000000414 12557303652 0021147 0 ustar 00root root 0000000 0000000 unless File.method_defined? :size
class File
def size
stat.size
end
end
end
if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :size?
Backports.convert_first_argument_to_path File, :size
end
backports-3.6.6/lib/backports/1.9.1/file/socket.rb 0000664 0000000 0000000 00000000170 12557303652 0021464 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :socket?
end
backports-3.6.6/lib/backports/1.9.1/file/split.rb 0000664 0000000 0000000 00000000166 12557303652 0021334 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :split
end
backports-3.6.6/lib/backports/1.9.1/file/stat.rb 0000664 0000000 0000000 00000000165 12557303652 0021153 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :stat
end
backports-3.6.6/lib/backports/1.9.1/file/sticky.rb 0000664 0000000 0000000 00000000170 12557303652 0021502 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :sticky?
end
backports-3.6.6/lib/backports/1.9.1/file/symlink.rb 0000664 0000000 0000000 00000000265 12557303652 0021667 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_all_arguments_to_path File, :symlink, 0
Backports.convert_first_argument_to_path File, :symlink?
end
backports-3.6.6/lib/backports/1.9.1/file/to_path.rb 0000664 0000000 0000000 00000000125 12557303652 0021632 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method File, :to_path, :path
backports-3.6.6/lib/backports/1.9.1/file/truncate.rb 0000664 0000000 0000000 00000000171 12557303652 0022022 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :truncate
end
backports-3.6.6/lib/backports/1.9.1/file/unlink.rb 0000664 0000000 0000000 00000000171 12557303652 0021475 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_all_arguments_to_path File, :unlink, 0
end
backports-3.6.6/lib/backports/1.9.1/file/writable.rb 0000664 0000000 0000000 00000000172 12557303652 0022007 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :writable?
end
backports-3.6.6/lib/backports/1.9.1/file/writable_real.rb 0000664 0000000 0000000 00000000177 12557303652 0023017 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :writable_real?
end
backports-3.6.6/lib/backports/1.9.1/file/zero.rb 0000664 0000000 0000000 00000000166 12557303652 0021160 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools/path'
Backports.convert_first_argument_to_path File, :zero?
end
backports-3.6.6/lib/backports/1.9.1/float.rb 0000664 0000000 0000000 00000000117 12557303652 0020363 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/float/ 0000775 0000000 0000000 00000000000 12557303652 0020037 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/float/round.rb 0000664 0000000 0000000 00000001126 12557303652 0021513 0 ustar 00root root 0000000 0000000 if Float.instance_method(:round).arity.zero?
require 'backports/tools/alias_method_chain'
require 'backports/tools/arguments'
class Float
def round_with_digits(ndigits=0)
ndigits = Backports::coerce_to_int(ndigits)
case
when ndigits == 0
round_without_digits
when ndigits < 0
p = 10 ** -ndigits
p > abs ? 0 : (self / p).round * p
else
p = 10 ** ndigits
prod = self * p
prod.infinite? || prod.nan? ? self : prod.round.to_f / p
end
end
Backports.alias_method_chain self, :round, :digits
end
end
backports-3.6.6/lib/backports/1.9.1/hash.rb 0000664 0000000 0000000 00000000117 12557303652 0020201 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/hash/ 0000775 0000000 0000000 00000000000 12557303652 0017655 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/hash/assoc.rb 0000664 0000000 0000000 00000000321 12557303652 0021306 0 ustar 00root root 0000000 0000000 unless Hash.method_defined? :assoc
class Hash
def assoc(key)
val = fetch(key) do
return find do |k, v|
[k, v] if k == key
end
end
[key, val]
end
end
end
backports-3.6.6/lib/backports/1.9.1/hash/default_proc.rb 0000664 0000000 0000000 00000000515 12557303652 0022652 0 ustar 00root root 0000000 0000000 unless Hash.method_defined? :default_proc=
require 'backports/tools/arguments'
class Hash
def default_proc=(proc)
if proc == nil # nil accepted in Ruby 2.0
self.default = nil
self
else
replace(Hash.new(&Backports.coerce_to(proc, Proc, :to_proc)).merge!(self))
end
end
end
end
backports-3.6.6/lib/backports/1.9.1/hash/key.rb 0000664 0000000 0000000 00000000122 12557303652 0020765 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method Hash, :key, :index
backports-3.6.6/lib/backports/1.9.1/hash/rassoc.rb 0000664 0000000 0000000 00000000264 12557303652 0021476 0 ustar 00root root 0000000 0000000 unless Hash.method_defined? :rassoc
class Hash
def rassoc(value)
k = key(value)
v = fetch(k){return nil}
[k, fetch(k)] if k || v == value
end
end
end
backports-3.6.6/lib/backports/1.9.1/hash/try_convert.rb 0000664 0000000 0000000 00000000235 12557303652 0022560 0 ustar 00root root 0000000 0000000 unless Hash.respond_to? :try_convert
require 'backports/tools/arguments'
def Hash.try_convert(x)
Backports.try_convert(x, Hash, :to_hash)
end
end
backports-3.6.6/lib/backports/1.9.1/integer.rb 0000664 0000000 0000000 00000000117 12557303652 0020713 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/integer/ 0000775 0000000 0000000 00000000000 12557303652 0020367 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/integer/magnitude.rb 0000664 0000000 0000000 00000000131 12557303652 0022664 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method Integer, :magnitude, :abs
backports-3.6.6/lib/backports/1.9.1/integer/round.rb 0000664 0000000 0000000 00000001303 12557303652 0022040 0 ustar 00root root 0000000 0000000 if Integer.instance_method(:round).arity.zero?
require 'backports/tools/alias_method_chain'
require 'backports/tools/arguments'
class Integer
def round_with_digits(ndigits=0)
ndigits = Backports::coerce_to_int(ndigits)
case
when ndigits.zero?
self
when ndigits > 0
raise RangeError if ndigits >= 1<<31
Float(self)
else
pow = 10 ** (-ndigits)
return 0 if pow.is_a?(Float) # when ndigits hugely negative
remain = self % pow
comp = self < 0 ? :<= : :<
remain -= pow unless remain.send(comp, pow / 2)
self - remain
end
end
Backports.alias_method_chain self, :round, :digits
end
end
backports-3.6.6/lib/backports/1.9.1/io.rb 0000664 0000000 0000000 00000000117 12557303652 0017665 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/io/ 0000775 0000000 0000000 00000000000 12557303652 0017341 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/io/binread.rb 0000664 0000000 0000000 00000000346 12557303652 0021275 0 ustar 00root root 0000000 0000000 unless IO.respond_to? :binread
require 'backports/tools/path'
def IO.binread(file, length = nil, offset = 0)
File.open(Backports.convert_path(file),"rb") do |f|
f.seek(offset)
f.read(length)
end
end
end
backports-3.6.6/lib/backports/1.9.1/io/open.rb 0000664 0000000 0000000 00000001156 12557303652 0020632 0 ustar 00root root 0000000 0000000 fd = IO.sysopen(__FILE__)
begin
IO.open(fd, :mode => 'r'){}
rescue TypeError
require 'backports/tools/io'
require 'backports/tools/alias_method_chain'
class << IO
def open_with_options_hash(*args)
if args.size > 2 || args[1].respond_to?(:to_hash)
fd, mode, options = (args << Backports::Undefined)
args = [fd, Backports.combine_mode_and_option(mode, options)]
end
if block_given?
open_without_options_hash(*args){|f| yield f}
else
open_without_options_hash(*args)
end
end
Backports.alias_method_chain self, :open, :options_hash
end
end
backports-3.6.6/lib/backports/1.9.1/io/try_convert.rb 0000664 0000000 0000000 00000000231 12557303652 0022240 0 ustar 00root root 0000000 0000000 unless IO.respond_to? :try_convert
require 'backports/tools/arguments'
def IO.try_convert(obj)
Backports.try_convert(obj, IO, :to_io)
end
end
backports-3.6.6/lib/backports/1.9.1/io/ungetbyte.rb 0000664 0000000 0000000 00000000127 12557303652 0021674 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method IO, :ungetbyte, :ungetc
backports-3.6.6/lib/backports/1.9.1/kernel.rb 0000664 0000000 0000000 00000000117 12557303652 0020536 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/kernel/ 0000775 0000000 0000000 00000000000 12557303652 0020212 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/kernel/__callee__.rb 0000664 0000000 0000000 00000000234 12557303652 0022557 0 ustar 00root root 0000000 0000000 unless (__callee__ || true rescue false)
require 'backports/1.8.7/kernel/__method__'
module Kernel
alias_method :__callee__, :__method__
end
end
backports-3.6.6/lib/backports/1.9.1/kernel/define_singleton_method.rb 0000664 0000000 0000000 00000000327 12557303652 0025415 0 ustar 00root root 0000000 0000000 unless Kernel.method_defined? :define_singleton_method
module Kernel
def define_singleton_method(*args, &block)
class << self
self
end.send(:define_method, *args, &block)
end
end
end
backports-3.6.6/lib/backports/1.9.1/kernel/public_method.rb 0000664 0000000 0000000 00000000452 12557303652 0023356 0 ustar 00root root 0000000 0000000 unless Kernel.method_defined? :public_method
module Kernel
def public_method(meth)
if respond_to?(meth) && !protected_methods.include?(meth.to_s)
method(meth)
else
raise NameError, "undefined method `#{meth}' for class `#{self.class}'"
end
end
end
end
backports-3.6.6/lib/backports/1.9.1/kernel/public_send.rb 0000664 0000000 0000000 00000000732 12557303652 0023030 0 ustar 00root root 0000000 0000000 unless Kernel.method_defined? :public_send
module Kernel
def public_send(method, *args, &block)
if respond_to?(method) && !protected_methods.include?(method.to_s)
send(method, *args, &block)
else
:foo.generate_a_no_method_error_in_preparation_for_method_missing rescue nil
# otherwise a NameError might be raised when we call method_missing ourselves
method_missing(method.to_sym, *args, &block)
end
end
end
end
backports-3.6.6/lib/backports/1.9.1/kernel/require_relative.rb 0000664 0000000 0000000 00000000705 12557303652 0024110 0 ustar 00root root 0000000 0000000 unless Kernel.private_method_defined? :require_relative
require 'backports/tools/path'
module Kernel
def require_relative(relative_feature)
file = caller.first.split(/:\d/,2).first
if /\A\((.*)\)/ =~ file # eval, etc.
raise LoadError, "require_relative is called in #{$1}"
end
require File.expand_path(Backports.convert_path(relative_feature), File.dirname(file))
end
private :require_relative
end
end
backports-3.6.6/lib/backports/1.9.1/math.rb 0000664 0000000 0000000 00000000117 12557303652 0020207 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/math/ 0000775 0000000 0000000 00000000000 12557303652 0017663 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/math/log.rb 0000664 0000000 0000000 00000001650 12557303652 0020773 0 ustar 00root root 0000000 0000000 unless (Math.log(2, 2) rescue false)
require 'backports/tools/alias_method_chain'
require 'backports/tools/arguments'
class << Math
# Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
def log_with_optional_base(numeric, base = Backports::Undefined)
if base.equal?(Backports::Undefined)
# Math.log(n) in 1.9.1 no longer accepts string arguments as it
# did on 1.8.x, but we won't risk redefining existing behavior
# when called with just one argument.
log_without_optional_base(numeric)
else
# Math.log(n, b) in 1.9.1 does not accept string arguments:
raise TypeError, "can't convert String into Float" if numeric.is_a?(String) || base.is_a?(String)
log_without_optional_base(numeric) / log_without_optional_base(base)
end
end
Backports.alias_method_chain self, :log, :optional_base
end
end
backports-3.6.6/lib/backports/1.9.1/math/log2.rb 0000664 0000000 0000000 00000000133 12557303652 0021050 0 ustar 00root root 0000000 0000000 unless Math.respond_to? :log2
def Math.log2(numeric)
log(numeric) / log(2)
end
end
backports-3.6.6/lib/backports/1.9.1/numeric.rb 0000664 0000000 0000000 00000000117 12557303652 0020720 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/numeric/ 0000775 0000000 0000000 00000000000 12557303652 0020374 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/numeric/round.rb 0000664 0000000 0000000 00000000575 12557303652 0022057 0 ustar 00root root 0000000 0000000 if Numeric.instance_method(:round).arity.zero?
require 'backports/tools/arguments'
require 'backports/tools/alias_method_chain'
class Numeric
def round_with_digits(ndigits=0)
ndigits = Backports::coerce_to_int(ndigits)
ndigits.zero? ? round_without_digits : Float(self).round(ndigits)
end
Backports.alias_method_chain self, :round, :digits
end
end
backports-3.6.6/lib/backports/1.9.1/proc.rb 0000664 0000000 0000000 00000000117 12557303652 0020221 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/proc/ 0000775 0000000 0000000 00000000000 12557303652 0017675 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/proc/case_compare.rb 0000664 0000000 0000000 00000000270 12557303652 0022642 0 ustar 00root root 0000000 0000000 unless Proc.new{true} === 42
class Proc
# Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Proc.html]
alias_method :===, :call
end
end
backports-3.6.6/lib/backports/1.9.1/proc/curry.rb 0000664 0000000 0000000 00000001204 12557303652 0021363 0 ustar 00root root 0000000 0000000 unless Proc.method_defined? :curry
require 'backports/1.9.1/proc/lambda'
class Proc
def curry(argc = nil)
min_argc = arity < 0 ? -arity - 1 : arity
argc ||= min_argc
if lambda? and arity < 0 ? argc < min_argc : argc != arity
raise ArgumentError, "wrong number of arguments (#{argc} for #{min_argc})"
end
creator = lambda? ? :lambda : :proc
block = send(creator) do |*args|
if args.size >= argc
call(*args)
else
send(creator) do |*more_args|
args += more_args
block.call(*args)
end
end
end
end
end
end
backports-3.6.6/lib/backports/1.9.1/proc/lambda.rb 0000664 0000000 0000000 00000002073 12557303652 0021444 0 ustar 00root root 0000000 0000000 unless Proc.method_defined? :lambda?
require 'backports/tools/alias_method_chain'
class Proc
# Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Proc.html]
def lambda?
!!__is_lambda__
end
attr_accessor :__is_lambda__
private :__is_lambda__
private :__is_lambda__=
end
class Method
def to_proc_with_lambda_tracking
proc = to_proc_without_lambda_tracking
proc.send :__is_lambda__=, true
proc
end
Backports.alias_method_chain self, :to_proc, :lambda_tracking
end
module Kernel
def lambda_with_lambda_tracking(&block)
l = lambda_without_lambda_tracking(&block)
l.send :__is_lambda__=, true unless block.send(:__is_lambda__) == false
l
end
def proc_with_lambda_tracking(&block)
l = proc_without_lambda_tracking(&block)
l.send :__is_lambda__=, block.send(:__is_lambda__) == true
l
end
Backports.alias_method_chain self, :lambda, :lambda_tracking
Backports.alias_method_chain self, :proc, :lambda_tracking
end
end
backports-3.6.6/lib/backports/1.9.1/proc/yield.rb 0000664 0000000 0000000 00000000123 12557303652 0021324 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method Proc, :yield, :call
backports-3.6.6/lib/backports/1.9.1/range.rb 0000664 0000000 0000000 00000000117 12557303652 0020352 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/range/ 0000775 0000000 0000000 00000000000 12557303652 0020026 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/range/cover.rb 0000664 0000000 0000000 00000000131 12557303652 0021464 0 ustar 00root root 0000000 0000000 require 'backports/tools/alias_method'
Backports.alias_method Range, :cover?, :include?
backports-3.6.6/lib/backports/1.9.1/regexp.rb 0000664 0000000 0000000 00000000117 12557303652 0020550 0 ustar 00root root 0000000 0000000 require 'backports/tools/require_relative_dir'
Backports.require_relative_dir
backports-3.6.6/lib/backports/1.9.1/regexp/ 0000775 0000000 0000000 00000000000 12557303652 0020224 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/regexp/try_convert.rb 0000664 0000000 0000000 00000000251 12557303652 0023125 0 ustar 00root root 0000000 0000000 unless Regexp.respond_to? :try_convert
require 'backports/tools/arguments'
def Regexp.try_convert(obj)
Backports.try_convert(obj, Regexp, :to_regexp)
end
end
backports-3.6.6/lib/backports/1.9.1/stdlib.rb 0000664 0000000 0000000 00000000042 12557303652 0020534 0 ustar 00root root 0000000 0000000 Backports::StdLib.extend_relative
backports-3.6.6/lib/backports/1.9.1/stdlib/ 0000775 0000000 0000000 00000000000 12557303652 0020213 5 ustar 00root root 0000000 0000000 backports-3.6.6/lib/backports/1.9.1/stdlib/prime.rb 0000664 0000000 0000000 00000033007 12557303652 0021657 0 ustar 00root root 0000000 0000000 #
# = prime.rb
#
# Prime numbers and factorization library.
#
# Copyright::
# Copyright (c) 1998-2008 Keiju ISHITSUKA(SHL Japan Inc.)
# Copyright (c) 2008 Yuki Sonoda (Yugui)
#
# Documentation::
# Yuki Sonoda
#
require "singleton"
require "forwardable"
class Integer
# Re-composes a prime factorization and returns the product.
#
# See Prime#int_from_prime_division for more details.
def Integer.from_prime_division(pd)
Prime.int_from_prime_division(pd)
end
# Returns the factorization of +self+.
#
# See Prime#prime_division for more details.
def prime_division(generator = Prime::Generator23.new)
Prime.prime_division(self, generator)
end
# Returns true if +self+ is a prime number, false for a composite.
def prime?
Prime.prime?(self)
end
# Iterates the given block over all prime numbers.
#
# See +Prime+#each for more details.
def Integer.each_prime(ubound, &block) # :yields: prime
Prime.each(ubound, &block)
end
end
#
# The set of all prime numbers.
#
# == Example
# Prime.each(100) do |prime|
# p prime #=> 2, 3, 5, 7, 11, ...., 97
# end
#
# == Retrieving the instance
# +Prime+.new is obsolete. Now +Prime+ has the default instance and you can
# access it as +Prime+.instance.
#
# For convenience, each instance method of +Prime+.instance can be accessed
# as a class method of +Prime+.
#
# e.g.
# Prime.instance.prime?(2) #=> true
# Prime.prime?(2) #=> true
#
# == Generators
# A "generator" provides an implementation of enumerating pseudo-prime
# numbers and it remembers the position of enumeration and upper bound.
# Futhermore, it is a external iterator of prime enumeration which is
# compatible to an Enumerator.
#
# +Prime+::+PseudoPrimeGenerator+ is the base class for generators.
# There are few implementations of generator.
#
# [+Prime+::+EratosthenesGenerator+]
# Uses eratosthenes's sieve.
# [+Prime+::+TrialDivisionGenerator+]
# Uses the trial division method.
# [+Prime+::+Generator23+]
# Generates all positive integers which is not divided by 2 nor 3.
# This sequence is very bad as a pseudo-prime sequence. But this
# is faster and uses much less memory than other generators. So,
# it is suitable for factorizing an integer which is not large but
# has many prime factors. e.g. for Prime#prime? .
class Prime
unless Prime.const_defined? :OldCompatibility
include Enumerable
@the_instance = Prime.new
# obsolete. Use +Prime+::+instance+ or class methods of +Prime+.
def initialize
@generator = EratosthenesGenerator.new
extend OldCompatibility
warn "Prime::new is obsolete. use Prime::instance or class methods of Prime."
end
class << self
extend Forwardable
include Enumerable
# Returns the default instance of Prime.
def instance; @the_instance end
def method_added(method) # :nodoc:
(class<< self;self;end).def_delegator :instance, method
end
end
# Iterates the given block over all prime numbers.
#
# == Parameters
# +ubound+::
# Optional. An arbitrary positive number.
# The upper bound of enumeration. The method enumerates
# prime numbers infinitely if +ubound+ is nil.
# +generator+::
# Optional. An implementation of pseudo-prime generator.
#
# == Return value
# An evaluated value of the given block at the last time.
# Or an enumerator which is compatible to an +Enumerator+
# if no block given.
#
# == Description
# Calls +block+ once for each prime number, passing the prime as
# a parameter.
#
# +ubound+::
# Upper bound of prime numbers. The iterator stops after
# yields all prime numbers p <= +ubound+.
#
# == Note
# +Prime+.+new+ returns a object extended by +Prime+::+OldCompatibility+
# in order to compatibility to Ruby 1.8, and +Prime+#each is overwritten
# by +Prime+::+OldCompatibility+#+each+.
#
# +Prime+.+new+ is now obsolete. Use +Prime+.+instance+.+each+ or simply
# +Prime+.+each+.
def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
generator.upper_bound = ubound
generator.each(&block)
end
# Returns true if +value+ is prime, false for a composite.
#
# == Parameters
# +value+:: an arbitrary integer to be checked.
# +generator+:: optional. A pseudo-prime generator.
def prime?(value, generator = Prime::Generator23.new)
value = -value if value < 0
return false if value < 2
for num in generator
q,r = value.divmod num
return true if q < num
return false if r == 0
end
end
# Re-composes a prime factorization and returns the product.
#
# == Parameters
# +pd+:: Array of pairs of integers. The each internal
# pair consists of a prime number -- a prime factor --
# and a natural number -- an exponent.
#
# == Example
# For [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]], it returns
# p_1**e_1 * p_2**e_2 * .... * p_n**e_n.
#
# Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
def int_from_prime_division(pd)
pd.inject(1){|value, (prime, index)|
value *= prime**index
}
end
# Returns the factorization of +value+.
#
# == Parameters
# +value+:: An arbitrary integer.
# +generator+:: Optional. A pseudo-prime generator.
# +generator+.succ must return the next
# pseudo-prime number in the ascendent
# order. It must generate all prime numbers,
# but may generate non prime numbers.
#
# === Exceptions
# +ZeroDivisionError+:: when +value+ is zero.
#
# == Example
# For an arbitrary integer
# n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
# prime_division(n) returns
# [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
#
# Prime.prime_division(12) #=> [[2,2], [3,1]]
#
def prime_division(value, generator= Prime::Generator23.new)
raise ZeroDivisionError if value == 0
if value < 0
value = -value
pv = [[-1, 1]]
else
pv = []
end
for prime in generator
count = 0
while (value1, mod = value.divmod(prime)
mod) == 0
value = value1
count += 1
end
if count != 0
pv.push [prime, count]
end
break if value1 <= prime
end
if value > 1
pv.push [value, 1]
end
return pv
end
# An abstract class for enumerating pseudo-prime numbers.
#
# Concrete subclasses should override succ, next, rewind.
class PseudoPrimeGenerator
include Enumerable
def initialize(ubound = nil)
@ubound = ubound
end
def upper_bound=(ubound)
@ubound = ubound
end
def upper_bound
@ubound
end
# returns the next pseudo-prime number, and move the internal
# position forward.
#
# +PseudoPrimeGenerator+#succ raises +NotImplementedError+.
def succ
raise NotImplementedError, "need to define `succ'"
end
# alias of +succ+.
def next
raise NotImplementedError, "need to define `next'"
end
# Rewinds the internal position for enumeration.
#
# See +Enumerator+#rewind.
def rewind
raise NotImplementedError, "need to define `rewind'"
end
# Iterates the given block for each prime numbers.
def each(&block)
return self.dup unless block
if @ubound
last_value = nil
loop do
prime = succ
break last_value if prime > @ubound
last_value = block.call(prime)
end
else
loop do
block.call(succ)
end
end
end
# see +Enumerator+#with_index.
alias with_index each_with_index
# see +Enumerator+#with_object.
def with_object(obj)
return enum_for(:with_object) unless block_given?
each do |prime|
yield prime, obj
end
end
end
# An implementation of +PseudoPrimeGenerator+.
#
# Uses +EratosthenesSieve+.
class EratosthenesGenerator < PseudoPrimeGenerator
def initialize
@last_prime = nil
super
end
def succ
@last_prime = @last_prime ? EratosthenesSieve.instance.next_to(@last_prime) : 2
end
def rewind
initialize
end
alias next succ
end
# An implementation of +PseudoPrimeGenerator+ which uses
# a prime table generated by trial division.
class TrialDivisionGenerator= @primes.length
# Only check for prime factors up to the square root of the potential primes,
# but without the performance hit of an actual square root calculation.
if @next_to_check + 4 > @ulticheck_next_squared
@ulticheck_index += 1
@ulticheck_next_squared = @primes.at(@ulticheck_index + 1) ** 2
end
# Only check numbers congruent to one and five, modulo six. All others
# are divisible by two or three. This also allows us to skip checking against
# two and three.
@primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
@next_to_check += 4
@primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
@next_to_check += 2
end
return @primes[index]
end
end
# Internal use. An implementation of eratosthenes's sieve
class EratosthenesSieve
include Singleton
BITS_PER_ENTRY = 16 # each entry is a set of 16-bits in a Fixnum
NUMS_PER_ENTRY = BITS_PER_ENTRY * 2 # twiced because even numbers are omitted
ENTRIES_PER_TABLE = 8
NUMS_PER_TABLE = NUMS_PER_ENTRY * ENTRIES_PER_TABLE
FILLED_ENTRY = (1 << NUMS_PER_ENTRY) - 1
def initialize # :nodoc:
# bitmap for odd prime numbers less than 256.
# For an arbitrary odd number n, @tables[i][j][k] is
# * 1 if n is prime,
# * 0 if n is composite,
# where i,j,k = indices(n)
@tables = [[0xcb6e, 0x64b4, 0x129a, 0x816d, 0x4c32, 0x864a, 0x820d, 0x2196].freeze]
end
# returns the least odd prime number which is greater than +n+.
def next_to(n)
n = (n-1).div(2)*2+3 # the next odd number to given n
table_index, integer_index, bit_index = indices(n)
loop do
extend_table until @tables.length > table_index
for j in integer_index...ENTRIES_PER_TABLE
if !@tables[table_index][j].zero?
for k in bit_index...BITS_PER_ENTRY
return NUMS_PER_TABLE*table_index + NUMS_PER_ENTRY*j + 2*k+1 if !@tables[table_index][j][k].zero?
end
end
bit_index = 0
end
table_index += 1; integer_index = 0
end
end
private
# for an odd number +n+, returns (i, j, k) such that @tables[i][j][k] represents primarity of the number
def indices(n)
# binary digits of n: |0|1|2|3|4|5|6|7|8|9|10|11|....
# indices: |-| k | j | i
# because of NUMS_PER_ENTRY, NUMS_PER_TABLE
k = (n & 0b00011111) >> 1
j = (n & 0b11100000) >> 5
i = n >> 8
return i, j, k
end
def extend_table
lbound = NUMS_PER_TABLE * @tables.length
ubound = lbound + NUMS_PER_TABLE
new_table = [FILLED_ENTRY] * ENTRIES_PER_TABLE # which represents primarity in lbound...ubound
(3..Integer(Math.sqrt(ubound))).step(2) do |p|
i, j, k = indices(p)
next if @tables[i][j][k].zero?
start = (lbound.div(p)+1)*p # least multiple of p which is >= lbound
start += p if start.even?
(start...ubound).step(2*p) do |n|
_, j, k = indices(n)
new_table[j] &= FILLED_ENTRY^(1<