}[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 1.9 are also. Some features of 2.0.0 are backported too.
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.
== 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, JRuby and Rubinius.
= Complete List of backports
== Ruby 1.8.7
Complete Ruby 1.8.7 backporting (core language). Refer to the official list of changes[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)
To include _only_ these backports, require "backports/1.8.7"
== Ruby 1.8.8
Ruby 1.8.8 has been officially cancelled. As of version 2.2, require "backports/1.8.8" does nothing.
== Ruby 1.9.1
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.9.2
Finally, most of Ruby 1.9.2 features have been backported:
* 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)
To include _only_ these backports and earlier, require "backports/1.9.2"
== Ruby 1.9.3
Some features of Ruby 1.9.3 have been backported:
* File
* +NULL+
* IO
* +advise+ (acts as a noop)
* +write+, +binwrite+
* String
* +byteslice+
* +prepend+
To include all Ruby backports but not those of Ruby 2.0 or Rails, require "backports/1.9.3" (or "backports/1.9")
== Ruby 2.0.0
Some features of Ruby 2.0.0 have been backported:
* Array
* +bsearch+
* Enumerable
* +lazy+
* Enumerator::Lazy
* all methods
* Hash
* default_proc= (with nil argument)
* +to_h+
* nil.to_h
* Range
* +bsearch+
* Struct
* +to_h+
To include all Ruby backports but not those of Rails, require "backports/2.0" (or "backports/2.0.0")
== Rails
Some generic methods from Rails methods have been copied:
* Enumerable
* +sum+
* Hash
* +symbolize_keys+, symbolize_keys!
* +reverse_merge+, reverse_merge!
* Module
* +alias_method_chain+
* Object
* +try+
* String
* +camelize+, +underscore+
* +dasherize+, +demodulize+
* +constantize+
To include _only_ these Rails backports but not those of Ruby, require "backports/rails".
== Libraries
Libraries are slowly being backported. You simply require them as usual, ideally (but not necessarily) after requiring backports.
require "backports"
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/]
== 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.3.5/Rakefile 0000664 0000000 0000000 00000007414 12225570245 0015171 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}
-C spec
rubyspec/core/#{path}_spec.rb
].join(' '), path
end
end
backports-3.3.5/backports.gemspec 0000664 0000000 0000000 00000001512 12225570245 0017052 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.0.0 for earlier versions.}
gem.summary = %q{Backports of Ruby features for older Ruby.}
gem.homepage = "http://github.com/marcandre/backports"
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.3.5/default.mspec 0000664 0000000 0000000 00000000600 12225570245 0016167 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.3.5/lib/ 0000775 0000000 0000000 00000000000 12225570245 0014264 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports.rb 0000664 0000000 0000000 00000000150 12225570245 0016575 0 ustar 00root root 0000000 0000000 require "backports/tools"
require "backports/version"
require "backports/2.0"
require "backports/rails"
backports-3.3.5/lib/backports/ 0000775 0000000 0000000 00000000000 12225570245 0016254 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7.rb 0000664 0000000 0000000 00000000165 12225570245 0017256 0 ustar 00root root 0000000 0000000 # require this file to load all the backports of Ruby 1.8.7
require "backports/tools"
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/ 0000775 0000000 0000000 00000000000 12225570245 0016727 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/argf.rb 0000664 0000000 0000000 00000000072 12225570245 0020172 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/argf/ 0000775 0000000 0000000 00000000000 12225570245 0017646 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/argf/bytes.rb 0000664 0000000 0000000 00000000051 12225570245 0021315 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/argf/each_byte'
backports-3.3.5/lib/backports/1.8.7/argf/chars.rb 0000664 0000000 0000000 00000000051 12225570245 0021267 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/argf/each_char'
backports-3.3.5/lib/backports/1.8.7/argf/each.rb 0000664 0000000 0000000 00000000157 12225570245 0021076 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional ARGF, :each, :force => true if RUBY_VERSION < '1.8.7'
backports-3.3.5/lib/backports/1.8.7/argf/each_byte.rb 0000664 0000000 0000000 00000000271 12225570245 0022116 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.8.7'
require 'backports/tools'
class << ARGF
Backports.make_block_optional ARGF, :each_byte, :force => true
alias_method :bytes, :each_byte
end
end
backports-3.3.5/lib/backports/1.8.7/argf/each_char.rb 0000664 0000000 0000000 00000001450 12225570245 0022070 0 ustar 00root root 0000000 0000000 unless ARGF.respond_to? :each_char
require 'backports/tools'
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.3.5/lib/backports/1.8.7/argf/each_line.rb 0000664 0000000 0000000 00000000164 12225570245 0022103 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional ARGF, :each_line, :force => true if RUBY_VERSION < '1.8.7'
backports-3.3.5/lib/backports/1.8.7/argf/getbyte.rb 0000664 0000000 0000000 00000000134 12225570245 0021634 0 ustar 00root root 0000000 0000000 require 'backports/tools'
class << ARGF
Backports.alias_method self, :getbyte, :getc
end
backports-3.3.5/lib/backports/1.8.7/argf/lines.rb 0000664 0000000 0000000 00000000137 12225570245 0021306 0 ustar 00root root 0000000 0000000 require 'backports/tools'
class << ARGF
Backports.alias_method self, :lines, :each_line
end
backports-3.3.5/lib/backports/1.8.7/argf/readbyte.rb 0000664 0000000 0000000 00000000141 12225570245 0021766 0 ustar 00root root 0000000 0000000 require 'backports/tools'
class << ARGF
Backports.alias_method self, :readbyte, :readchar
end
backports-3.3.5/lib/backports/1.8.7/array.rb 0000664 0000000 0000000 00000000072 12225570245 0020371 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/array/ 0000775 0000000 0000000 00000000000 12225570245 0020045 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/array/collect.rb 0000664 0000000 0000000 00000000134 12225570245 0022015 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Array, :collect!, :test_on => [42]
backports-3.3.5/lib/backports/1.8.7/array/combination.rb 0000664 0000000 0000000 00000001706 12225570245 0022700 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :combination
require 'backports/tools'
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.3.5/lib/backports/1.8.7/array/cycle.rb 0000664 0000000 0000000 00000000515 12225570245 0021472 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :cycle
require 'backports/tools'
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.3.5/lib/backports/1.8.7/array/delete_if.rb 0000664 0000000 0000000 00000000135 12225570245 0022311 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Array, :delete_if, :test_on => [42]
backports-3.3.5/lib/backports/1.8.7/array/each.rb 0000664 0000000 0000000 00000000130 12225570245 0021264 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Array, :each, :test_on => [42]
backports-3.3.5/lib/backports/1.8.7/array/each_index.rb 0000664 0000000 0000000 00000000136 12225570245 0022461 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Array, :each_index, :test_on => [42]
backports-3.3.5/lib/backports/1.8.7/array/find_index.rb 0000664 0000000 0000000 00000000046 12225570245 0022501 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/array/index'
backports-3.3.5/lib/backports/1.8.7/array/flatten.rb 0000664 0000000 0000000 00000002532 12225570245 0022031 0 ustar 00root root 0000000 0000000 unless ([[]].flatten(1) rescue false)
require 'backports/tools'
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.3.5/lib/backports/1.8.7/array/index.rb 0000664 0000000 0000000 00000000706 12225570245 0021504 0 ustar 00root root 0000000 0000000 unless ([1].index{true} rescue false)
require 'backports/tools'
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.3.5/lib/backports/1.8.7/array/map.rb 0000664 0000000 0000000 00000000130 12225570245 0021141 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Array, :map!, :test_on => [42]
backports-3.3.5/lib/backports/1.8.7/array/permutation.rb 0000664 0000000 0000000 00000001455 12225570245 0022746 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :permutation
require 'backports/tools'
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.3.5/lib/backports/1.8.7/array/pop.rb 0000664 0000000 0000000 00000000725 12225570245 0021174 0 ustar 00root root 0000000 0000000 unless ([1].pop(1) rescue false)
require 'backports/tools'
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.3.5/lib/backports/1.8.7/array/product.rb 0000664 0000000 0000000 00000001613 12225570245 0022053 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :product
require 'backports/tools'
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.3.5/lib/backports/1.8.7/array/reject.rb 0000664 0000000 0000000 00000000144 12225570245 0021645 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Array, :reject, :reject!, :test_on => [42]
backports-3.3.5/lib/backports/1.8.7/array/reverse_each.rb 0000664 0000000 0000000 00000000140 12225570245 0023020 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Array, :reverse_each, :test_on => [42]
backports-3.3.5/lib/backports/1.8.7/array/rindex.rb 0000664 0000000 0000000 00000000665 12225570245 0021672 0 ustar 00root root 0000000 0000000 unless ([1].rindex{true} rescue false)
class Array
require 'backports/tools'
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.3.5/lib/backports/1.8.7/array/select.rb 0000664 0000000 0000000 00000000132 12225570245 0021645 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Array, :select, :test_on => [42]
backports-3.3.5/lib/backports/1.8.7/array/shift.rb 0000664 0000000 0000000 00000000637 12225570245 0021515 0 ustar 00root root 0000000 0000000 unless ([1].shift(1) rescue false)
class Array
require 'backports/tools'
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.3.5/lib/backports/1.8.7/array/shuffle.rb 0000664 0000000 0000000 00000000653 12225570245 0022032 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.3.5/lib/backports/1.8.7/binding.rb 0000664 0000000 0000000 00000000072 12225570245 0020665 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/binding/ 0000775 0000000 0000000 00000000000 12225570245 0020341 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/binding/eval.rb 0000664 0000000 0000000 00000000204 12225570245 0021611 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.3.5/lib/backports/1.8.7/dir.rb 0000664 0000000 0000000 00000000072 12225570245 0020031 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/dir/ 0000775 0000000 0000000 00000000000 12225570245 0017505 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/dir/each.rb 0000664 0000000 0000000 00000000404 12225570245 0020730 0 ustar 00root root 0000000 0000000 require 'backports/tools'
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.3.5/lib/backports/1.8.7/dir/foreach.rb 0000664 0000000 0000000 00000000453 12225570245 0021443 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.3.5/lib/backports/1.8.7/enumerable.rb 0000664 0000000 0000000 00000000072 12225570245 0021372 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/enumerable/ 0000775 0000000 0000000 00000000000 12225570245 0021046 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/enumerable/count.rb 0000664 0000000 0000000 00000000562 12225570245 0022526 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :count
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/cycle.rb 0000664 0000000 0000000 00000001053 12225570245 0022471 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :cycle
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/detect.rb 0000664 0000000 0000000 00000000137 12225570245 0022644 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Enumerable, :detect, :test_on => 1..2
backports-3.3.5/lib/backports/1.8.7/enumerable/drop.rb 0000664 0000000 0000000 00000000455 12225570245 0022343 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :drop
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/drop_while.rb 0000664 0000000 0000000 00000000644 12225570245 0023533 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.3.5/lib/backports/1.8.7/enumerable/each_cons.rb 0000664 0000000 0000000 00000000257 12225570245 0023321 0 ustar 00root root 0000000 0000000 require 'backports/tools'
require 'enumerator' unless Enumerable.method_defined? :each_cons
Backports.make_block_optional Enumerable, :each_cons, :test_on => 1..2, :arg => 1
backports-3.3.5/lib/backports/1.8.7/enumerable/each_slice.rb 0000664 0000000 0000000 00000000261 12225570245 0023451 0 ustar 00root root 0000000 0000000 require 'backports/tools'
require 'enumerator' unless Enumerable.method_defined? :each_slice
Backports.make_block_optional Enumerable, :each_slice, :test_on => 1..2, :arg => 1
backports-3.3.5/lib/backports/1.8.7/enumerable/each_with_index.rb 0000664 0000000 0000000 00000000150 12225570245 0024511 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Enumerable, :each_with_index, :test_on => 1..2
backports-3.3.5/lib/backports/1.8.7/enumerable/entries.rb 0000664 0000000 0000000 00000000516 12225570245 0023046 0 ustar 00root root 0000000 0000000 if Enumerable.instance_method(:entries).arity.zero?
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/find.rb 0000664 0000000 0000000 00000000135 12225570245 0022312 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Enumerable, :find, :test_on => 1..2
backports-3.3.5/lib/backports/1.8.7/enumerable/find_all.rb 0000664 0000000 0000000 00000000141 12225570245 0023137 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Enumerable, :find_all, :test_on => 1..2
backports-3.3.5/lib/backports/1.8.7/enumerable/find_index.rb 0000664 0000000 0000000 00000000751 12225570245 0023505 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :find_index
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/first.rb 0000664 0000000 0000000 00000000767 12225570245 0022534 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :first
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/group_by.rb 0000664 0000000 0000000 00000000446 12225570245 0023225 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.3.5/lib/backports/1.8.7/enumerable/inject.rb 0000664 0000000 0000000 00000000670 12225570245 0022652 0 ustar 00root root 0000000 0000000 unless ((1..2).inject(:+) rescue false)
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/max_by.rb 0000664 0000000 0000000 00000000644 12225570245 0022656 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :max_by
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/min_by.rb 0000664 0000000 0000000 00000000644 12225570245 0022654 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :min_by
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/minmax.rb 0000664 0000000 0000000 00000001067 12225570245 0022670 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :minmax
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/minmax_by.rb 0000664 0000000 0000000 00000001272 12225570245 0023360 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :minmax_by
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerable/none.rb 0000664 0000000 0000000 00000000171 12225570245 0022331 0 ustar 00root root 0000000 0000000 unless Enumerable.method_defined? :none?
module Enumerable
def none?(&block)
!any?(&block)
end
end
end
backports-3.3.5/lib/backports/1.8.7/enumerable/one.rb 0000664 0000000 0000000 00000000665 12225570245 0022163 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.3.5/lib/backports/1.8.7/enumerable/partition.rb 0000664 0000000 0000000 00000000142 12225570245 0023401 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Enumerable, :partition, :test_on => 1..2
backports-3.3.5/lib/backports/1.8.7/enumerable/reduce.rb 0000664 0000000 0000000 00000000054 12225570245 0022641 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/enumerable/inject'
backports-3.3.5/lib/backports/1.8.7/enumerable/reject.rb 0000664 0000000 0000000 00000000137 12225570245 0022650 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Enumerable, :reject, :test_on => 1..2
backports-3.3.5/lib/backports/1.8.7/enumerable/reverse_each.rb 0000664 0000000 0000000 00000000500 12225570245 0024021 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.3.5/lib/backports/1.8.7/enumerable/select.rb 0000664 0000000 0000000 00000000137 12225570245 0022653 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Enumerable, :select, :test_on => 1..2
backports-3.3.5/lib/backports/1.8.7/enumerable/sort_by.rb 0000664 0000000 0000000 00000000140 12225570245 0023047 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Enumerable, :sort_by, :test_on => 1..2
backports-3.3.5/lib/backports/1.8.7/enumerable/take.rb 0000664 0000000 0000000 00000000233 12225570245 0022315 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.3.5/lib/backports/1.8.7/enumerable/take_while.rb 0000664 0000000 0000000 00000000616 12225570245 0023512 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.3.5/lib/backports/1.8.7/enumerable/to_a.rb 0000664 0000000 0000000 00000000526 12225570245 0022320 0 ustar 00root root 0000000 0000000 if Enumerable.instance_method(:to_a).arity.zero?
require 'backports/tools'
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.3.5/lib/backports/1.8.7/enumerator.rb 0000664 0000000 0000000 00000000072 12225570245 0021434 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/enumerator/ 0000775 0000000 0000000 00000000000 12225570245 0021110 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/enumerator/each.rb 0000664 0000000 0000000 00000000271 12225570245 0022335 0 ustar 00root root 0000000 0000000 unless Object.const_defined? :Enumerator
require 'backports/tools'
require 'enumerator'
Backports.make_block_optional Enumerable::Enumerator, :each, :test_on => [42].to_enum
end
backports-3.3.5/lib/backports/1.8.7/enumerator/next.rb 0000664 0000000 0000000 00000000607 12225570245 0022416 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.3.5/lib/backports/1.8.7/enumerator/rewind.rb 0000664 0000000 0000000 00000000466 12225570245 0022733 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.3.5/lib/backports/1.8.7/enumerator/with_index.rb 0000664 0000000 0000000 00000000614 12225570245 0023600 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.3.5/lib/backports/1.8.7/env.rb 0000664 0000000 0000000 00000000072 12225570245 0020043 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/env/ 0000775 0000000 0000000 00000000000 12225570245 0017517 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/env/delete_if.rb 0000664 0000000 0000000 00000000132 12225570245 0021760 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional ENV, :delete_if, :test_on => ENV
backports-3.3.5/lib/backports/1.8.7/env/each.rb 0000664 0000000 0000000 00000000125 12225570245 0020742 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional ENV, :each, :test_on => ENV
backports-3.3.5/lib/backports/1.8.7/env/each_key.rb 0000664 0000000 0000000 00000000131 12225570245 0021607 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional ENV, :each_key, :test_on => ENV
backports-3.3.5/lib/backports/1.8.7/env/each_pair.rb 0000664 0000000 0000000 00000000132 12225570245 0021753 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional ENV, :each_pair, :test_on => ENV
backports-3.3.5/lib/backports/1.8.7/env/each_value.rb 0000664 0000000 0000000 00000000133 12225570245 0022135 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional ENV, :each_value, :test_on => ENV
backports-3.3.5/lib/backports/1.8.7/env/reject.rb 0000664 0000000 0000000 00000000224 12225570245 0021316 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional ENV, :reject, :test_on => ENV
Backports.make_block_optional ENV, :reject!, :test_on => ENV
backports-3.3.5/lib/backports/1.8.7/env/select.rb 0000664 0000000 0000000 00000000127 12225570245 0021323 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional ENV, :select, :test_on => ENV
backports-3.3.5/lib/backports/1.8.7/fixnum.rb 0000664 0000000 0000000 00000000072 12225570245 0020561 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/fixnum/ 0000775 0000000 0000000 00000000000 12225570245 0020235 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/fixnum/div.rb 0000664 0000000 0000000 00000000151 12225570245 0021341 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.3.5/lib/backports/1.8.7/fixnum/fdiv.rb 0000664 0000000 0000000 00000000144 12225570245 0021511 0 ustar 00root root 0000000 0000000 unless Fixnum.method_defined? :fdiv
class Fixnum
def fdiv(n)
to_f / n
end
end
end
backports-3.3.5/lib/backports/1.8.7/float.rb 0000664 0000000 0000000 00000000072 12225570245 0020360 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/float/ 0000775 0000000 0000000 00000000000 12225570245 0020034 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/float/fdiv.rb 0000664 0000000 0000000 00000000115 12225570245 0021306 0 ustar 00root root 0000000 0000000 unless Float.method_defined? :fdiv
Float.send :alias_method, :fdiv, :/
end
backports-3.3.5/lib/backports/1.8.7/gc.rb 0000664 0000000 0000000 00000000072 12225570245 0017644 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/gc/ 0000775 0000000 0000000 00000000000 12225570245 0017320 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/gc/stress.rb 0000664 0000000 0000000 00000000176 12225570245 0021174 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.3.5/lib/backports/1.8.7/hash.rb 0000664 0000000 0000000 00000000072 12225570245 0020176 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/hash/ 0000775 0000000 0000000 00000000000 12225570245 0017652 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/hash/constructor.rb 0000664 0000000 0000000 00000001263 12225570245 0022566 0 ustar 00root root 0000000 0000000 unless (Hash[[[:test, :test]]] rescue false)
require 'backports/tools'
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.3.5/lib/backports/1.8.7/hash/delete_if.rb 0000664 0000000 0000000 00000000154 12225570245 0022117 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Hash, :delete_if, :test_on => {:hello => "world!"}
backports-3.3.5/lib/backports/1.8.7/hash/each.rb 0000664 0000000 0000000 00000000147 12225570245 0021101 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Hash, :each, :test_on => {:hello => "world!"}
backports-3.3.5/lib/backports/1.8.7/hash/each_key.rb 0000664 0000000 0000000 00000000153 12225570245 0021746 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Hash, :each_key, :test_on => {:hello => "world!"}
backports-3.3.5/lib/backports/1.8.7/hash/each_pair.rb 0000664 0000000 0000000 00000000154 12225570245 0022112 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Hash, :each_pair, :test_on => {:hello => "world!"}
backports-3.3.5/lib/backports/1.8.7/hash/each_value.rb 0000664 0000000 0000000 00000000155 12225570245 0022274 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Hash, :each_value, :test_on => {:hello => "world!"}
backports-3.3.5/lib/backports/1.8.7/hash/eql.rb 0000664 0000000 0000000 00000000044 12225570245 0020756 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/hash/hash'
backports-3.3.5/lib/backports/1.8.7/hash/hash.rb 0000664 0000000 0000000 00000000505 12225570245 0021122 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.3.5/lib/backports/1.8.7/hash/reject.rb 0000664 0000000 0000000 00000000163 12225570245 0021453 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Hash, :reject, :reject!, :test_on => {:hello => "world!"}
backports-3.3.5/lib/backports/1.8.7/hash/select.rb 0000664 0000000 0000000 00000000151 12225570245 0021453 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Hash, :select, :test_on => {:hello => "world!"}
backports-3.3.5/lib/backports/1.8.7/integer.rb 0000664 0000000 0000000 00000000072 12225570245 0020710 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/integer/ 0000775 0000000 0000000 00000000000 12225570245 0020364 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/integer/downto.rb 0000664 0000000 0000000 00000000146 12225570245 0022224 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Integer, :downto, :test_on => 42, :arg => 42
backports-3.3.5/lib/backports/1.8.7/integer/even.rb 0000664 0000000 0000000 00000000152 12225570245 0021644 0 ustar 00root root 0000000 0000000 unless Integer.method_defined? :even?
class Integer
def even?
self[0].zero?
end
end
end
backports-3.3.5/lib/backports/1.8.7/integer/odd.rb 0000664 0000000 0000000 00000000151 12225570245 0021454 0 ustar 00root root 0000000 0000000 unless Integer.method_defined? :odd?
class Integer
def odd?
!self[0].zero?
end
end
end
backports-3.3.5/lib/backports/1.8.7/integer/ord.rb 0000664 0000000 0000000 00000000135 12225570245 0021474 0 ustar 00root root 0000000 0000000 unless Integer.method_defined? :ord
class Integer
def ord
self
end
end
end
backports-3.3.5/lib/backports/1.8.7/integer/pred.rb 0000664 0000000 0000000 00000000143 12225570245 0021641 0 ustar 00root root 0000000 0000000 unless Integer.method_defined? :pred
class Integer
def pred
self - 1
end
end
end
backports-3.3.5/lib/backports/1.8.7/integer/times.rb 0000664 0000000 0000000 00000000131 12225570245 0022025 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Integer, :times, :test_on => 42
backports-3.3.5/lib/backports/1.8.7/integer/upto.rb 0000664 0000000 0000000 00000000144 12225570245 0021677 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Integer, :upto, :test_on => 42, :arg => 42
backports-3.3.5/lib/backports/1.8.7/io.rb 0000664 0000000 0000000 00000000072 12225570245 0017662 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/io/ 0000775 0000000 0000000 00000000000 12225570245 0017336 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/io/bytes.rb 0000664 0000000 0000000 00000000047 12225570245 0021012 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/io/each_byte'
backports-3.3.5/lib/backports/1.8.7/io/chars.rb 0000664 0000000 0000000 00000000047 12225570245 0020764 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/io/each_char'
backports-3.3.5/lib/backports/1.8.7/io/each.rb 0000664 0000000 0000000 00000000155 12225570245 0020564 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional IO, :each, :force => true if RUBY_VERSION < '1.8.7'
backports-3.3.5/lib/backports/1.8.7/io/each_byte.rb 0000664 0000000 0000000 00000000244 12225570245 0021606 0 ustar 00root root 0000000 0000000 require 'backports/tools'
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.3.5/lib/backports/1.8.7/io/each_char.rb 0000664 0000000 0000000 00000001371 12225570245 0021562 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.3.5/lib/backports/1.8.7/io/each_line.rb 0000664 0000000 0000000 00000000244 12225570245 0021572 0 ustar 00root root 0000000 0000000 require 'backports/tools'
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.3.5/lib/backports/1.8.7/io/foreach.rb 0000664 0000000 0000000 00000000220 12225570245 0021264 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.8.7'
require 'backports/tools'
class << IO
Backports.make_block_optional self, :foreach, :force => true
end
end
backports-3.3.5/lib/backports/1.8.7/io/getbyte.rb 0000664 0000000 0000000 00000000106 12225570245 0021323 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method IO, :getbyte, :getc
backports-3.3.5/lib/backports/1.8.7/io/lines.rb 0000664 0000000 0000000 00000000047 12225570245 0020776 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/io/each_line'
backports-3.3.5/lib/backports/1.8.7/io/readbyte.rb 0000664 0000000 0000000 00000000113 12225570245 0021455 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method IO, :readbyte, :readchar
backports-3.3.5/lib/backports/1.8.7/kernel.rb 0000664 0000000 0000000 00000000072 12225570245 0020533 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/kernel/ 0000775 0000000 0000000 00000000000 12225570245 0020207 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/kernel/__method__.rb 0000664 0000000 0000000 00000000230 12225570245 0022603 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.3.5/lib/backports/1.8.7/kernel/instance_exec.rb 0000664 0000000 0000000 00000000433 12225570245 0023344 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.3.5/lib/backports/1.8.7/kernel/tap.rb 0000664 0000000 0000000 00000000155 12225570245 0021321 0 ustar 00root root 0000000 0000000 unless Kernel.method_defined? :tap
module Kernel
def tap
yield self
self
end
end
end
backports-3.3.5/lib/backports/1.8.7/method.rb 0000664 0000000 0000000 00000000072 12225570245 0020533 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/method/ 0000775 0000000 0000000 00000000000 12225570245 0020207 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/method/name.rb 0000664 0000000 0000000 00000002543 12225570245 0021460 0 ustar 00root root 0000000 0000000 unless Method.method_defined? :name
require 'backports/tools'
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.3.5/lib/backports/1.8.7/module.rb 0000664 0000000 0000000 00000000072 12225570245 0020540 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/module/ 0000775 0000000 0000000 00000000000 12225570245 0020214 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/module/class_exec.rb 0000664 0000000 0000000 00000000055 12225570245 0022652 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/module/module_exec'
backports-3.3.5/lib/backports/1.8.7/module/module_exec.rb 0000664 0000000 0000000 00000000431 12225570245 0023030 0 ustar 00root root 0000000 0000000 unless Module.method_defined? :module_exec
require 'backports/tools'
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.3.5/lib/backports/1.8.7/numeric.rb 0000664 0000000 0000000 00000000072 12225570245 0020715 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/numeric/ 0000775 0000000 0000000 00000000000 12225570245 0020371 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/numeric/step.rb 0000664 0000000 0000000 00000000152 12225570245 0021667 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Numeric, :step, :test_on => 42, :arg => [100, 6]
backports-3.3.5/lib/backports/1.8.7/object_space.rb 0000664 0000000 0000000 00000000072 12225570245 0021674 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/object_space/ 0000775 0000000 0000000 00000000000 12225570245 0021350 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/object_space/each_object.rb 0000664 0000000 0000000 00000000200 12225570245 0024113 0 ustar 00root root 0000000 0000000 require 'backports/tools'
class << ObjectSpace
Backports.make_block_optional self, :each_object, :test_on => ObjectSpace
end
backports-3.3.5/lib/backports/1.8.7/process.rb 0000664 0000000 0000000 00000000072 12225570245 0020731 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/process/ 0000775 0000000 0000000 00000000000 12225570245 0020405 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/process/exec.rb 0000664 0000000 0000000 00000000044 12225570245 0021654 0 ustar 00root root 0000000 0000000 class << Process
public :exec
end
backports-3.3.5/lib/backports/1.8.7/range.rb 0000664 0000000 0000000 00000000072 12225570245 0020347 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/range/ 0000775 0000000 0000000 00000000000 12225570245 0020023 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/range/each.rb 0000664 0000000 0000000 00000000133 12225570245 0021245 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Range, :each, :test_on => 69..666
backports-3.3.5/lib/backports/1.8.7/range/step.rb 0000664 0000000 0000000 00000000147 12225570245 0021325 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Range, :step, :test_on => 69..666, :arg => 42
backports-3.3.5/lib/backports/1.8.7/regexp.rb 0000664 0000000 0000000 00000000072 12225570245 0020545 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/regexp/ 0000775 0000000 0000000 00000000000 12225570245 0020221 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/regexp/union.rb 0000664 0000000 0000000 00000000510 12225570245 0021672 0 ustar 00root root 0000000 0000000 unless (Regexp.union(%w(a b)) rescue false)
require 'backports/tools'
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.3.5/lib/backports/1.8.7/stdlib.rb 0000664 0000000 0000000 00000000042 12225570245 0020531 0 ustar 00root root 0000000 0000000 Backports::StdLib.extend_relative
backports-3.3.5/lib/backports/1.8.7/stdlib/ 0000775 0000000 0000000 00000000000 12225570245 0020210 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb 0000664 0000000 0000000 00000002072 12225570245 0022035 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.3.5/lib/backports/1.8.7/stop_iteration.rb 0000664 0000000 0000000 00000000524 12225570245 0022320 0 ustar 00root root 0000000 0000000 require 'backports/tools'
unless Object.const_defined? :StopIteration
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.3.5/lib/backports/1.8.7/string.rb 0000664 0000000 0000000 00000000072 12225570245 0020561 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/string/ 0000775 0000000 0000000 00000000000 12225570245 0020235 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/string/bytes.rb 0000664 0000000 0000000 00000000053 12225570245 0021706 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/string/each_byte'
backports-3.3.5/lib/backports/1.8.7/string/bytesize.rb 0000664 0000000 0000000 00000000115 12225570245 0022415 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method String, :bytesize, :length
backports-3.3.5/lib/backports/1.8.7/string/each.rb 0000664 0000000 0000000 00000000211 12225570245 0021454 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional String, :each, :test_on => "abc" if "is there still an each?".respond_to? :each
backports-3.3.5/lib/backports/1.8.7/string/each_byte.rb 0000664 0000000 0000000 00000000222 12225570245 0022501 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional String, :each_byte, :test_on => "abc"
Backports.alias_method String, :bytes, :each_byte
backports-3.3.5/lib/backports/1.8.7/string/each_char.rb 0000664 0000000 0000000 00000000431 12225570245 0022455 0 ustar 00root root 0000000 0000000 unless String.method_defined? :each_char
require 'backports/tools'
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.3.5/lib/backports/1.8.7/string/each_line.rb 0000664 0000000 0000000 00000000222 12225570245 0022465 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional String, :each_line, :test_on => "abc"
Backports.alias_method String, :lines, :each_line
backports-3.3.5/lib/backports/1.8.7/string/end_with.rb 0000664 0000000 0000000 00000000434 12225570245 0022364 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.3.5/lib/backports/1.8.7/string/lines.rb 0000664 0000000 0000000 00000000053 12225570245 0021672 0 ustar 00root root 0000000 0000000 require 'backports/1.8.7/string/each_line'
backports-3.3.5/lib/backports/1.8.7/string/partition.rb 0000664 0000000 0000000 00000001321 12225570245 0022570 0 ustar 00root root 0000000 0000000 unless ("check partition".partition(" ") rescue false)
require 'backports/tools'
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.3.5/lib/backports/1.8.7/string/rpartition.rb 0000664 0000000 0000000 00000001004 12225570245 0022750 0 ustar 00root root 0000000 0000000 unless String.method_defined? :rpartition
require 'backports/tools'
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.3.5/lib/backports/1.8.7/string/start_with.rb 0000664 0000000 0000000 00000000423 12225570245 0022751 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.3.5/lib/backports/1.8.7/string/upto.rb 0000664 0000000 0000000 00000000654 12225570245 0021556 0 ustar 00root root 0000000 0000000 unless ("abc".upto("def", true){} rescue false)
require 'backports/tools'
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.3.5/lib/backports/1.8.7/struct.rb 0000664 0000000 0000000 00000000072 12225570245 0020577 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/struct/ 0000775 0000000 0000000 00000000000 12225570245 0020253 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/struct/each.rb 0000664 0000000 0000000 00000000157 12225570245 0021503 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Struct, :each, :test_on => Struct.new(:foo, :bar).new
backports-3.3.5/lib/backports/1.8.7/struct/each_pair.rb 0000664 0000000 0000000 00000000164 12225570245 0022514 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.make_block_optional Struct, :each_pair, :test_on => Struct.new(:foo, :bar).new
backports-3.3.5/lib/backports/1.8.7/symbol.rb 0000664 0000000 0000000 00000000072 12225570245 0020560 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.8.7/symbol/ 0000775 0000000 0000000 00000000000 12225570245 0020234 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.8.7/symbol/to_proc.rb 0000664 0000000 0000000 00000000400 12225570245 0022220 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.3.5/lib/backports/1.8.8.rb 0000664 0000000 0000000 00000000131 12225570245 0017250 0 ustar 00root root 0000000 0000000 # require this file to load all the backports up to Ruby 1.8.8
require 'backports/1.8.7'
backports-3.3.5/lib/backports/1.8.rb 0000664 0000000 0000000 00000000137 12225570245 0017110 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.3.5/lib/backports/1.9.1.rb 0000664 0000000 0000000 00000000231 12225570245 0017243 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.3.5/lib/backports/1.9.1/ 0000775 0000000 0000000 00000000000 12225570245 0016722 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/array.rb 0000664 0000000 0000000 00000000072 12225570245 0020364 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/array/ 0000775 0000000 0000000 00000000000 12225570245 0020040 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/array/sample.rb 0000664 0000000 0000000 00000001007 12225570245 0021644 0 ustar 00root root 0000000 0000000 unless Array.method_defined? :sample
require 'backports/tools'
class Array
def sample(n = Backports::Undefined)
return self[Kernel.rand(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 + Kernel.rand(size - i)
result[i], result[r] = result[r], result[i]
end
result[n..size] = []
result
end
end
end
backports-3.3.5/lib/backports/1.9.1/array/try_convert.rb 0000664 0000000 0000000 00000000231 12225570245 0022737 0 ustar 00root root 0000000 0000000 unless Array.respond_to? :try_convert
require 'backports/tools'
def Array.try_convert(obj)
Backports.try_convert(obj, Array, :to_ary)
end
end
backports-3.3.5/lib/backports/1.9.1/dir.rb 0000664 0000000 0000000 00000000072 12225570245 0020024 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/dir/ 0000775 0000000 0000000 00000000000 12225570245 0017500 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/dir/to_path.rb 0000664 0000000 0000000 00000000107 12225570245 0021461 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method Dir, :to_path, :path
backports-3.3.5/lib/backports/1.9.1/enumerable.rb 0000664 0000000 0000000 00000000072 12225570245 0021365 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/enumerable/ 0000775 0000000 0000000 00000000000 12225570245 0021041 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/enumerable/each_with_index.rb 0000664 0000000 0000000 00000000661 12225570245 0024513 0 ustar 00root root 0000000 0000000 if Enumerable.instance_method(:each_with_index).arity.zero?
require 'backports/tools'
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.3.5/lib/backports/1.9.1/enumerable/each_with_object.rb 0000664 0000000 0000000 00000000351 12225570245 0024646 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.3.5/lib/backports/1.9.1/enumerator.rb 0000664 0000000 0000000 00000000072 12225570245 0021427 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/enumerator/ 0000775 0000000 0000000 00000000000 12225570245 0021103 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/enumerator/new.rb 0000664 0000000 0000000 00000002135 12225570245 0022222 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'
# 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.3.5/lib/backports/1.9.1/enumerator/with_object.rb 0000664 0000000 0000000 00000000371 12225570245 0023732 0 ustar 00root root 0000000 0000000 require 'backports/tools'
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.3.5/lib/backports/1.9.1/env.rb 0000664 0000000 0000000 00000000072 12225570245 0020036 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/env/ 0000775 0000000 0000000 00000000000 12225570245 0017512 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/env/key.rb 0000664 0000000 0000000 00000000130 12225570245 0020621 0 ustar 00root root 0000000 0000000 require 'backports/tools'
class << ENV
Backports.alias_method self, :key, :index
end
backports-3.3.5/lib/backports/1.9.1/file.rb 0000664 0000000 0000000 00000000072 12225570245 0020165 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/file/ 0000775 0000000 0000000 00000000000 12225570245 0017641 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/file/atime.rb 0000664 0000000 0000000 00000000161 12225570245 0021263 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :atime
end
backports-3.3.5/lib/backports/1.9.1/file/basename.rb 0000664 0000000 0000000 00000000164 12225570245 0021742 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :basename
end
backports-3.3.5/lib/backports/1.9.1/file/binary.rb 0000664 0000000 0000000 00000000207 12225570245 0021451 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.3.5/lib/backports/1.9.1/file/blockdev.rb 0000664 0000000 0000000 00000000165 12225570245 0021761 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :blockdev?
end
backports-3.3.5/lib/backports/1.9.1/file/chardev.rb 0000664 0000000 0000000 00000000164 12225570245 0021603 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :chardev?
end
backports-3.3.5/lib/backports/1.9.1/file/chmod.rb 0000664 0000000 0000000 00000000163 12225570245 0021260 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_all_arguments_to_path File, :chmod, 1
end
backports-3.3.5/lib/backports/1.9.1/file/chown.rb 0000664 0000000 0000000 00000000163 12225570245 0021304 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_all_arguments_to_path File, :chown, 2
end
backports-3.3.5/lib/backports/1.9.1/file/ctime.rb 0000664 0000000 0000000 00000000161 12225570245 0021265 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :ctime
end
backports-3.3.5/lib/backports/1.9.1/file/delete.rb 0000664 0000000 0000000 00000000164 12225570245 0021431 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_all_arguments_to_path File, :delete, 0
end
backports-3.3.5/lib/backports/1.9.1/file/directory.rb 0000664 0000000 0000000 00000000166 12225570245 0022175 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :directory?
end
backports-3.3.5/lib/backports/1.9.1/file/dirname.rb 0000664 0000000 0000000 00000000163 12225570245 0021605 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :dirname
end
backports-3.3.5/lib/backports/1.9.1/file/executable.rb 0000664 0000000 0000000 00000000167 12225570245 0022313 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :executable?
end
backports-3.3.5/lib/backports/1.9.1/file/executable_real.rb 0000664 0000000 0000000 00000000174 12225570245 0023314 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :executable_real?
end
backports-3.3.5/lib/backports/1.9.1/file/exist.rb 0000664 0000000 0000000 00000000162 12225570245 0021321 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :exist?
end
backports-3.3.5/lib/backports/1.9.1/file/exists.rb 0000664 0000000 0000000 00000000163 12225570245 0021505 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :exists?
end
backports-3.3.5/lib/backports/1.9.1/file/expand_path.rb 0000664 0000000 0000000 00000000673 12225570245 0022467 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
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.3.5/lib/backports/1.9.1/file/extname.rb 0000664 0000000 0000000 00000000163 12225570245 0021627 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :extname
end
backports-3.3.5/lib/backports/1.9.1/file/file.rb 0000664 0000000 0000000 00000000161 12225570245 0021103 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :file?
end
backports-3.3.5/lib/backports/1.9.1/file/ftype.rb 0000664 0000000 0000000 00000000161 12225570245 0021313 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :ftype
end
backports-3.3.5/lib/backports/1.9.1/file/grpowned.rb 0000664 0000000 0000000 00000000165 12225570245 0022015 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :grpowned?
end
backports-3.3.5/lib/backports/1.9.1/file/join.rb 0000664 0000000 0000000 00000000162 12225570245 0021124 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_all_arguments_to_path File, :join, 0
end
backports-3.3.5/lib/backports/1.9.1/file/lchmod.rb 0000664 0000000 0000000 00000000221 12225570245 0021427 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9' && File.respond_to?(:lchmod)
require 'backports/tools'
Backports.convert_all_arguments_to_path File, :lchmod, 1
end
backports-3.3.5/lib/backports/1.9.1/file/lchown.rb 0000664 0000000 0000000 00000000164 12225570245 0021461 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_all_arguments_to_path File, :lchown, 2
end
backports-3.3.5/lib/backports/1.9.1/file/link.rb 0000664 0000000 0000000 00000000160 12225570245 0021120 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :link
end
backports-3.3.5/lib/backports/1.9.1/file/lstat.rb 0000664 0000000 0000000 00000000161 12225570245 0021313 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :lstat
end
backports-3.3.5/lib/backports/1.9.1/file/mtime.rb 0000664 0000000 0000000 00000000161 12225570245 0021277 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :mtime
end
backports-3.3.5/lib/backports/1.9.1/file/new.rb 0000664 0000000 0000000 00000000157 12225570245 0020762 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :new
end
backports-3.3.5/lib/backports/1.9.1/file/open.rb 0000664 0000000 0000000 00000001232 12225570245 0021125 0 ustar 00root root 0000000 0000000 begin
File.open(__FILE__, :mode => 'r'){}
rescue TypeError
require 'backports/tools'
def open_with_options_hash(file, mode = nil, perm = Backports::Undefined, options = Backports::Undefined)
mode, perm = Backports.combine_mode_perm_and_option(mode, perm, 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
Backports.alias_method_chain File, :open, :options_hash
end
if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :open
end
backports-3.3.5/lib/backports/1.9.1/file/owned.rb 0000664 0000000 0000000 00000000162 12225570245 0021301 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :owned?
end
backports-3.3.5/lib/backports/1.9.1/file/pipe.rb 0000664 0000000 0000000 00000000161 12225570245 0021121 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :pipe?
end
backports-3.3.5/lib/backports/1.9.1/file/readable.rb 0000664 0000000 0000000 00000000165 12225570245 0021727 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :readable?
end
backports-3.3.5/lib/backports/1.9.1/file/readable_real.rb 0000664 0000000 0000000 00000000172 12225570245 0022730 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :readable_real?
end
backports-3.3.5/lib/backports/1.9.1/file/readlink.rb 0000664 0000000 0000000 00000000164 12225570245 0021760 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :readlink
end
backports-3.3.5/lib/backports/1.9.1/file/rename.rb 0000664 0000000 0000000 00000000162 12225570245 0021434 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :rename
end
backports-3.3.5/lib/backports/1.9.1/file/setgid.rb 0000664 0000000 0000000 00000000163 12225570245 0021445 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :setgid?
end
backports-3.3.5/lib/backports/1.9.1/file/setuid.rb 0000664 0000000 0000000 00000000163 12225570245 0021463 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :setuid?
end
backports-3.3.5/lib/backports/1.9.1/file/size.rb 0000664 0000000 0000000 00000000407 12225570245 0021141 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'
Backports.convert_first_argument_to_path File, :size?
Backports.convert_first_argument_to_path File, :size
end
backports-3.3.5/lib/backports/1.9.1/file/socket.rb 0000664 0000000 0000000 00000000163 12225570245 0021456 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :socket?
end
backports-3.3.5/lib/backports/1.9.1/file/split.rb 0000664 0000000 0000000 00000000161 12225570245 0021317 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :split
end
backports-3.3.5/lib/backports/1.9.1/file/stat.rb 0000664 0000000 0000000 00000000160 12225570245 0021136 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :stat
end
backports-3.3.5/lib/backports/1.9.1/file/sticky.rb 0000664 0000000 0000000 00000000163 12225570245 0021474 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :sticky?
end
backports-3.3.5/lib/backports/1.9.1/file/symlink.rb 0000664 0000000 0000000 00000000260 12225570245 0021652 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_all_arguments_to_path File, :symlink, 0
Backports.convert_first_argument_to_path File, :symlink?
end
backports-3.3.5/lib/backports/1.9.1/file/to_path.rb 0000664 0000000 0000000 00000000110 12225570245 0021614 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method File, :to_path, :path
backports-3.3.5/lib/backports/1.9.1/file/truncate.rb 0000664 0000000 0000000 00000000164 12225570245 0022014 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :truncate
end
backports-3.3.5/lib/backports/1.9.1/file/unlink.rb 0000664 0000000 0000000 00000000164 12225570245 0021467 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_all_arguments_to_path File, :unlink, 0
end
backports-3.3.5/lib/backports/1.9.1/file/writable.rb 0000664 0000000 0000000 00000000165 12225570245 0022001 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :writable?
end
backports-3.3.5/lib/backports/1.9.1/file/writable_real.rb 0000664 0000000 0000000 00000000172 12225570245 0023002 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :writable_real?
end
backports-3.3.5/lib/backports/1.9.1/file/zero.rb 0000664 0000000 0000000 00000000161 12225570245 0021143 0 ustar 00root root 0000000 0000000 if RUBY_VERSION < '1.9'
require 'backports/tools'
Backports.convert_first_argument_to_path File, :zero?
end
backports-3.3.5/lib/backports/1.9.1/float.rb 0000664 0000000 0000000 00000000072 12225570245 0020353 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/float/ 0000775 0000000 0000000 00000000000 12225570245 0020027 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/float/round.rb 0000664 0000000 0000000 00000001035 12225570245 0021502 0 ustar 00root root 0000000 0000000 if Float.instance_method(:round).arity.zero?
require 'backports/tools'
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.3.5/lib/backports/1.9.1/hash.rb 0000664 0000000 0000000 00000000072 12225570245 0020171 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/hash/ 0000775 0000000 0000000 00000000000 12225570245 0017645 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/hash/assoc.rb 0000664 0000000 0000000 00000000321 12225570245 0021276 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.3.5/lib/backports/1.9.1/hash/default_proc.rb 0000664 0000000 0000000 00000000503 12225570245 0022637 0 ustar 00root root 0000000 0000000 unless Hash.method_defined? :default_proc=
require 'backports/tools'
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.3.5/lib/backports/1.9.1/hash/key.rb 0000664 0000000 0000000 00000000105 12225570245 0020756 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method Hash, :key, :index
backports-3.3.5/lib/backports/1.9.1/hash/rassoc.rb 0000664 0000000 0000000 00000000264 12225570245 0021466 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.3.5/lib/backports/1.9.1/hash/try_convert.rb 0000664 0000000 0000000 00000000223 12225570245 0022545 0 ustar 00root root 0000000 0000000 unless Hash.respond_to? :try_convert
require 'backports/tools'
def Hash.try_convert(x)
Backports.try_convert(x, Hash, :to_hash)
end
end
backports-3.3.5/lib/backports/1.9.1/integer.rb 0000664 0000000 0000000 00000000072 12225570245 0020703 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/integer/ 0000775 0000000 0000000 00000000000 12225570245 0020357 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/integer/magnitude.rb 0000664 0000000 0000000 00000000114 12225570245 0022655 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method Integer, :magnitude, :abs
backports-3.3.5/lib/backports/1.9.1/integer/round.rb 0000664 0000000 0000000 00000001212 12225570245 0022027 0 ustar 00root root 0000000 0000000 if Integer.instance_method(:round).arity.zero?
require 'backports/tools'
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.3.5/lib/backports/1.9.1/io.rb 0000664 0000000 0000000 00000000072 12225570245 0017655 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/io/ 0000775 0000000 0000000 00000000000 12225570245 0017331 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/io/binread.rb 0000664 0000000 0000000 00000000341 12225570245 0021260 0 ustar 00root root 0000000 0000000 unless IO.respond_to? :binread
require 'backports/tools'
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.3.5/lib/backports/1.9.1/io/open.rb 0000664 0000000 0000000 00000001110 12225570245 0020610 0 ustar 00root root 0000000 0000000 begin
File.open(__FILE__) { |f| IO.open(f.fileno, :mode => 'r').close }
rescue TypeError
require 'backports/tools'
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.3.5/lib/backports/1.9.1/io/try_convert.rb 0000664 0000000 0000000 00000000217 12225570245 0022234 0 ustar 00root root 0000000 0000000 unless IO.respond_to? :try_convert
require 'backports/tools'
def IO.try_convert(obj)
Backports.try_convert(obj, IO, :to_io)
end
end
backports-3.3.5/lib/backports/1.9.1/io/ungetbyte.rb 0000664 0000000 0000000 00000000112 12225570245 0021656 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method IO, :ungetbyte, :ungetc
backports-3.3.5/lib/backports/1.9.1/kernel.rb 0000664 0000000 0000000 00000000072 12225570245 0020526 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/kernel/ 0000775 0000000 0000000 00000000000 12225570245 0020202 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/kernel/__callee__.rb 0000664 0000000 0000000 00000000234 12225570245 0022547 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.3.5/lib/backports/1.9.1/kernel/define_singleton_method.rb 0000664 0000000 0000000 00000000327 12225570245 0025405 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.3.5/lib/backports/1.9.1/kernel/public_method.rb 0000664 0000000 0000000 00000000452 12225570245 0023346 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.3.5/lib/backports/1.9.1/kernel/public_send.rb 0000664 0000000 0000000 00000000732 12225570245 0023020 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.3.5/lib/backports/1.9.1/kernel/require_relative.rb 0000664 0000000 0000000 00000000700 12225570245 0024073 0 ustar 00root root 0000000 0000000 unless Kernel.private_method_defined? :require_relative
require 'backports/tools'
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.3.5/lib/backports/1.9.1/math.rb 0000664 0000000 0000000 00000000072 12225570245 0020177 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/math/ 0000775 0000000 0000000 00000000000 12225570245 0017653 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/math/log.rb 0000664 0000000 0000000 00000001557 12225570245 0020771 0 ustar 00root root 0000000 0000000 unless (Math.log(2, 2) rescue false)
require 'backports/tools'
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.3.5/lib/backports/1.9.1/math/log2.rb 0000664 0000000 0000000 00000000133 12225570245 0021040 0 ustar 00root root 0000000 0000000 unless Math.respond_to? :log2
def Math.log2(numeric)
log(numeric) / log(2)
end
end
backports-3.3.5/lib/backports/1.9.1/numeric.rb 0000664 0000000 0000000 00000000072 12225570245 0020710 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/numeric/ 0000775 0000000 0000000 00000000000 12225570245 0020364 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/numeric/round.rb 0000664 0000000 0000000 00000000504 12225570245 0022037 0 ustar 00root root 0000000 0000000 if Numeric.instance_method(:round).arity.zero?
require 'backports/tools'
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.3.5/lib/backports/1.9.1/proc.rb 0000664 0000000 0000000 00000000072 12225570245 0020211 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/proc/ 0000775 0000000 0000000 00000000000 12225570245 0017665 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/proc/case_compare.rb 0000664 0000000 0000000 00000000270 12225570245 0022632 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.3.5/lib/backports/1.9.1/proc/curry.rb 0000664 0000000 0000000 00000001204 12225570245 0021353 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.3.5/lib/backports/1.9.1/proc/lambda.rb 0000664 0000000 0000000 00000002050 12225570245 0021427 0 ustar 00root root 0000000 0000000 unless Proc.method_defined? :lambda?
require 'backports/tools'
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.3.5/lib/backports/1.9.1/proc/yield.rb 0000664 0000000 0000000 00000000106 12225570245 0021315 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method Proc, :yield, :call
backports-3.3.5/lib/backports/1.9.1/range.rb 0000664 0000000 0000000 00000000072 12225570245 0020342 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/range/ 0000775 0000000 0000000 00000000000 12225570245 0020016 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/range/cover.rb 0000664 0000000 0000000 00000000114 12225570245 0021455 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.alias_method Range, :cover?, :include?
backports-3.3.5/lib/backports/1.9.1/regexp.rb 0000664 0000000 0000000 00000000072 12225570245 0020540 0 ustar 00root root 0000000 0000000 require 'backports/tools'
Backports.require_relative_dir
backports-3.3.5/lib/backports/1.9.1/regexp/ 0000775 0000000 0000000 00000000000 12225570245 0020214 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/regexp/try_convert.rb 0000664 0000000 0000000 00000000237 12225570245 0023121 0 ustar 00root root 0000000 0000000 unless Regexp.respond_to? :try_convert
require 'backports/tools'
def Regexp.try_convert(obj)
Backports.try_convert(obj, Regexp, :to_regexp)
end
end
backports-3.3.5/lib/backports/1.9.1/stdlib.rb 0000664 0000000 0000000 00000000042 12225570245 0020524 0 ustar 00root root 0000000 0000000 Backports::StdLib.extend_relative
backports-3.3.5/lib/backports/1.9.1/stdlib/ 0000775 0000000 0000000 00000000000 12225570245 0020203 5 ustar 00root root 0000000 0000000 backports-3.3.5/lib/backports/1.9.1/stdlib/prime.rb 0000664 0000000 0000000 00000033007 12225570245 0021647 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)