Commit f63d7999 authored by Jérémy Bobbio's avatar Jérémy Bobbio

Merge tag 'upstream/3.6.6'

Upstream version 3.6.6
parents 950dc105 b4f71ea3
......@@ -11,6 +11,7 @@ group :test do
gem 'mspec', :git => 'git://github.com/rubyspec/mspec.git'
gem 'activesupport'
gem 'minitest', '< 5.0.0', :require => false
gem 'test-unit'
end
# Declare any dependencies that are still in development here instead of in
......
......@@ -7,7 +7,7 @@ GIT
PATH
remote: .
specs:
backports (3.6.1)
backports (3.6.6)
GEM
remote: http://rubygems.org/
......@@ -19,6 +19,7 @@ GEM
minitest (4.7.5)
multi_json (1.7.2)
rake (10.1.0)
test-unit (2.1.1.0)
PLATFORMS
java
......@@ -30,3 +31,4 @@ DEPENDENCIES
minitest (< 5.0.0)
mspec!
rake
test-unit
......@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
gem.description = %q{Essential backports that enable many of the nice features of Ruby 1.8.7 up to 2.1.0 for earlier versions.}
gem.summary = %q{Backports of Ruby features for older Ruby.}
gem.homepage = "http://github.com/marcandre/backports"
gem.license = "MIT"
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
......
unless Enumerable.method_defined? :flat_map
require 'backports/1.8.7/array/flatten'
module Enumerable
def flat_map(&block)
def flat_map
return to_enum(:flat_map) unless block_given?
map(&block).flatten(1)
r = []
each do |*args|
result = yield(*args)
result.respond_to?(:to_ary) ? r.concat(result) : r.push(result)
end
r
end
alias_method :collect_concat, :flat_map
end
......
......@@ -30,7 +30,8 @@ unless String.method_defined? :byteslice
# Actual implementation:
str = unpack("@#{start}a#{len}").first
str = dup.replace(str) unless self.instance_of?(String) # Must return subclass
str.force_encoding(encoding)
str.force_encoding(encoding) if respond_to?(:encoding)
str
end
end
end
......@@ -2,6 +2,9 @@ unless Bignum.method_defined? :bit_length
require 'backports/2.0.0/range/bsearch'
class Bignum
def bit_length
# We use the fact that bignums use the minimum number of "words" necessary
# where "words" is some number of bytes <= to the size of a fixnum
# So we have (size - word_size) * 8 < bit_length <= size * 8
n = 8 * (size - 42.size)
smaller = self >> n
if smaller >= 0
......@@ -9,7 +12,7 @@ unless Bignum.method_defined? :bit_length
else
smaller = -smaller
end
n + (0...8 * 42.size).bsearch{|i| smaller <= (1 << i) }
n + (1..8 * 42.size).bsearch{|i| smaller <= (1 << i) }
end
end
end
......@@ -19,7 +19,7 @@ module Backports
def srand(new_seed = 0)
new_seed = Backports.coerce_to_int(new_seed)
old, @seed = @seed, new_seed.nonzero? || Random.new_seed
old, @seed = @seed, new_seed.nonzero? || ::Random.new_seed
@mt = MT19937[ @seed ]
old
end
......@@ -45,7 +45,7 @@ module Backports
end
def ==(other)
other.is_a?(Random) &&
other.is_a?(::Random) &&
seed == other.seed &&
left == other.send(:left) &&
state == other.send(:state)
......
module Backports
VERSION = "3.6.1" unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
VERSION = "3.6.6" unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
end
fails:Enumerable#collect_concat calls to_ary but not to_a
fails:Enumerable#flat_map calls to_ary but not to_a
require './test/test_helper'
class BitLengthTest < Test::Unit::TestCase
def test_big_num # Issue #95
require 'backports/2.1.0/bignum/bit_length'
r = 91178362617816881166579720176198217549251305244541026425489888079462471837807
assert_equal 256, r.bit_length
r = 57896044618658097711785492504343953926634992332820282019728792003956564819968
assert_equal 256, r.bit_length
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment