backports 3.10.3 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.travis.yml +3 -3
- data/README.rdoc +47 -13
- data/Rakefile +10 -0
- data/frozen_old_spec/tags/1.8.6/core/array/append_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.6/core/enumerable/all_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.6/core/enumerable/any_spec.rb +2 -0
- data/frozen_old_spec/tags/1.8.6/core/enumerable/none_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.6/core/enumerable/one_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.6/core/module/alias_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.6/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/1.8.6/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/1.8.6/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.6/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/1.8.6/core/module/define_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.6/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.6/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.7/core/array/append_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.7/core/enumerable/all_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.7/core/enumerable/any_spec.rb +2 -0
- data/frozen_old_spec/tags/1.8.7/core/enumerable/none_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.7/core/enumerable/one_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.7/core/module/alias_method_spec.rb +7 -0
- data/frozen_old_spec/tags/1.8.7/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/1.8.7/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/1.8.7/core/module/attr_spec.rb +2 -0
- data/frozen_old_spec/tags/1.8.7/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/1.8.7/core/module/define_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.8.7/core/module/remove_method_spec.rb +3 -0
- data/frozen_old_spec/tags/1.8.7/core/module/undef_method_spec.rb +3 -0
- data/frozen_old_spec/tags/1.8.7/core/struct/new_spec.rb +3 -0
- data/frozen_old_spec/tags/1.9.1/core/array/append_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.1/core/enumerable/all_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.1/core/enumerable/any_spec.rb +2 -0
- data/frozen_old_spec/tags/1.9.1/core/enumerable/none_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.1/core/enumerable/one_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.1/core/module/alias_method_spec.rb +4 -0
- data/frozen_old_spec/tags/1.9.1/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/1.9.1/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/1.9.1/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.1/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/1.9.1/core/module/define_method_spec.rb +3 -0
- data/frozen_old_spec/tags/1.9.1/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.1/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.2/core/array/append_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.2/core/enumerable/all_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.2/core/enumerable/any_spec.rb +2 -0
- data/frozen_old_spec/tags/1.9.2/core/enumerable/none_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.2/core/enumerable/one_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.2/core/module/alias_method_spec.rb +4 -0
- data/frozen_old_spec/tags/1.9.2/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/1.9.2/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/1.9.2/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.2/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/1.9.2/core/module/define_method_spec.rb +3 -0
- data/frozen_old_spec/tags/1.9.2/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.2/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.3/core/enumerable/any_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.3/core/module/alias_method_spec.rb +4 -0
- data/frozen_old_spec/tags/1.9.3/core/module/attr_accessor_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.3/core/module/attr_reader_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.3/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.3/core/module/attr_writer_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.3/core/module/define_method_spec.rb +3 -0
- data/frozen_old_spec/tags/1.9.3/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/1.9.3/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.0.0/core/enumerable/any_spec.rb +1 -0
- data/frozen_old_spec/tags/2.0.0/core/module/alias_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.0.0/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/2.0.0/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/2.0.0/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/2.0.0/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/2.0.0/core/module/define_method_spec.rb +2 -0
- data/frozen_old_spec/tags/2.0.0/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.0.0/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.0.0/core/struct/new_spec.rb +1 -0
- data/frozen_old_spec/tags/2.1.0/core/enumerable/any_spec.rb +1 -0
- data/frozen_old_spec/tags/2.1.0/core/module/alias_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.1.0/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/2.1.0/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/2.1.0/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/2.1.0/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/2.1.0/core/module/define_method_spec.rb +2 -0
- data/frozen_old_spec/tags/2.1.0/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.1.0/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.1.0/core/struct/new_spec.rb +1 -0
- data/frozen_old_spec/tags/2.2.0/core/enumerable/any_spec.rb +1 -0
- data/frozen_old_spec/tags/2.2.0/core/module/alias_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.2.0/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/2.2.0/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/2.2.0/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/2.2.0/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/2.2.0/core/module/define_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.2.0/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.2.0/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.2.0/core/struct/new_spec.rb +1 -0
- data/frozen_old_spec/tags/2.3.0/core/enumerable/any_spec.rb +1 -0
- data/frozen_old_spec/tags/2.3.0/core/module/alias_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.3.0/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/2.3.0/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/2.3.0/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/2.3.0/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/2.3.0/core/module/define_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.3.0/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.3.0/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.3.0/core/struct/new_spec.rb +1 -0
- data/frozen_old_spec/tags/2.3.5/core/struct/new_spec.rb +1 -0
- data/frozen_old_spec/tags/2.4.0/core/enumerable/any_spec.rb +1 -0
- data/frozen_old_spec/tags/2.4.0/core/module/alias_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.4.0/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/2.4.0/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/2.4.0/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/2.4.0/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/2.4.0/core/module/define_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.4.0/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.4.0/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.4.0/core/struct/new_spec.rb +1 -0
- data/frozen_old_spec/tags/2.5.0/core/enumerable/any_spec.rb +1 -0
- data/frozen_old_spec/tags/2.5.0/core/module/alias_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.5.0/core/module/attr_accessor_spec.rb +2 -0
- data/frozen_old_spec/tags/2.5.0/core/module/attr_reader_spec.rb +2 -0
- data/frozen_old_spec/tags/2.5.0/core/module/attr_spec.rb +1 -0
- data/frozen_old_spec/tags/2.5.0/core/module/attr_writer_spec.rb +2 -0
- data/frozen_old_spec/tags/2.5.0/core/module/define_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.5.0/core/module/remove_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.5.0/core/module/undef_method_spec.rb +1 -0
- data/frozen_old_spec/tags/2.5.0/core/nil/dup_spec.rb +1 -0
- data/frozen_old_spec/tags/2.5.0/core/struct/new_spec.rb +1 -0
- data/lib/backports/2.5.0.rb +3 -0
- data/lib/backports/2.5.0/array.rb +3 -0
- data/lib/backports/2.5.0/array/append.rb +3 -0
- data/lib/backports/2.5.0/array/prepend.rb +3 -0
- data/lib/backports/2.5.0/dir.rb +3 -0
- data/lib/backports/2.5.0/dir/children.rb +6 -0
- data/lib/backports/2.5.0/dir/each_child.rb +7 -0
- data/lib/backports/2.5.0/enumerable.rb +3 -0
- data/lib/backports/2.5.0/enumerable/all.rb +13 -0
- data/lib/backports/2.5.0/enumerable/any.rb +42 -0
- data/lib/backports/2.5.0/enumerable/none.rb +15 -0
- data/lib/backports/2.5.0/enumerable/one.rb +21 -0
- data/lib/backports/2.5.0/hash.rb +3 -0
- data/lib/backports/2.5.0/hash/slice.rb +7 -0
- data/lib/backports/2.5.0/hash/transform_keys.rb +19 -0
- data/lib/backports/2.5.0/integer.rb +3 -0
- data/lib/backports/2.5.0/integer/allbits.rb +8 -0
- data/lib/backports/2.5.0/integer/anybits.rb +8 -0
- data/lib/backports/2.5.0/integer/nobits.rb +8 -0
- data/lib/backports/2.5.0/integer/sqrt.rb +18 -0
- data/lib/backports/2.5.0/kernel.rb +3 -0
- data/lib/backports/2.5.0/kernel/yield_self.rb +6 -0
- data/lib/backports/2.5.0/module.rb +3 -0
- data/lib/backports/2.5.0/module/alias_method.rb +4 -0
- data/lib/backports/2.5.0/module/attr.rb +3 -0
- data/lib/backports/2.5.0/module/attr_accessor.rb +3 -0
- data/lib/backports/2.5.0/module/attr_reader.rb +3 -0
- data/lib/backports/2.5.0/module/attr_writer.rb +3 -0
- data/lib/backports/2.5.0/module/define_method.rb +3 -0
- data/lib/backports/2.5.0/module/remove_method.rb +3 -0
- data/lib/backports/2.5.0/module/undef_method.rb +3 -0
- data/lib/backports/2.5.0/string.rb +3 -0
- data/lib/backports/2.5.0/string/delete_prefix.rb +32 -0
- data/lib/backports/2.5.0/string/delete_suffix.rb +33 -0
- data/lib/backports/2.5.0/struct.rb +3 -0
- data/lib/backports/2.5.0/struct/new.rb +24 -0
- data/lib/backports/2.5.rb +2 -0
- data/lib/backports/latest.rb +2 -0
- data/lib/backports/version.rb +1 -1
- data/set_version/2.5.0.rb +1 -0
- data/set_version/setter.rb +8 -0
- data/spec/tags/1.9.1/core/dir/each_child_spec.rb +1 -0
- data/spec/tags/1.9.1/core/hash/transform_keys_spec.rb +2 -0
- data/spec/tags/1.9.1/core/io/write_spec.rb +1 -0
- data/spec/tags/1.9.1/core/kernel/yield_self_spec.rb +1 -0
- data/spec/tags/1.9.1/core/method/curry_spec.rb +1 -0
- data/spec/tags/1.9.1/core/module/alias_method_spec.rb +3 -0
- data/spec/tags/1.9.1/core/module/attr_accessor_spec.rb +1 -0
- data/spec/tags/1.9.1/core/module/attr_reader_spec.rb +1 -0
- data/spec/tags/1.9.1/core/module/attr_writer_spec.rb +1 -0
- data/spec/tags/1.9.1/core/module/define_method_spec.rb +7 -0
- data/spec/tags/1.9.1/core/struct/new_spec.rb +2 -0
- data/spec/tags/1.9.2/core/dir/each_child_spec.rb +1 -0
- data/spec/tags/1.9.2/core/hash/transform_keys_spec.rb +2 -0
- data/spec/tags/1.9.2/core/kernel/yield_self_spec.rb +1 -0
- data/spec/tags/1.9.2/core/module/alias_method_spec.rb +3 -0
- data/spec/tags/1.9.2/core/module/attr_accessor_spec.rb +1 -0
- data/spec/tags/1.9.2/core/module/attr_reader_spec.rb +1 -0
- data/spec/tags/1.9.2/core/module/attr_writer_spec.rb +1 -0
- data/spec/tags/1.9.2/core/module/define_method_spec.rb +7 -0
- data/spec/tags/1.9.2/core/struct/new_spec.rb +2 -0
- data/spec/tags/1.9.3/core/dir/each_child_spec.rb +1 -0
- data/spec/tags/1.9.3/core/hash/transform_keys_spec.rb +2 -0
- data/spec/tags/1.9.3/core/hash/transform_values_spec.rb +2 -0
- data/spec/tags/1.9.3/core/kernel/yield_self_spec.rb +1 -0
- data/spec/tags/1.9.3/core/module/alias_method_spec.rb +3 -0
- data/spec/tags/1.9.3/core/module/attr_accessor_spec.rb +1 -0
- data/spec/tags/1.9.3/core/module/attr_reader_spec.rb +1 -0
- data/spec/tags/1.9.3/core/module/attr_writer_spec.rb +1 -0
- data/spec/tags/1.9.3/core/module/define_method_spec.rb +7 -0
- data/spec/tags/1.9.3/core/struct/new_spec.rb +2 -0
- data/spec/tags/2.0.0/core/module/attr_accessor_spec.rb +1 -0
- data/spec/tags/2.0.0/core/module/attr_reader_spec.rb +1 -0
- data/spec/tags/2.0.0/core/module/attr_writer_spec.rb +1 -0
- data/spec/tags/2.0.0/core/module/define_method_spec.rb +4 -0
- data/spec/tags/2.0.0/core/struct/new_spec.rb +1 -0
- data/spec/tags/2.1.0/core/module/attr_accessor_spec.rb +1 -0
- data/spec/tags/2.1.0/core/module/attr_reader_spec.rb +1 -0
- data/spec/tags/2.1.0/core/module/attr_writer_spec.rb +1 -0
- data/spec/tags/2.1.0/core/module/define_method_spec.rb +4 -0
- data/spec/tags/2.1.0/core/struct/new_spec.rb +1 -0
- data/spec/tags/2.2.0/core/module/attr_accessor_spec.rb +1 -0
- data/spec/tags/2.2.0/core/module/attr_reader_spec.rb +1 -0
- data/spec/tags/2.2.0/core/module/attr_writer_spec.rb +1 -0
- data/spec/tags/2.2.0/core/module/define_method_spec.rb +4 -0
- data/spec/tags/2.2.0/core/struct/new_spec.rb +1 -0
- data/spec/tags/2.3.0/core/struct/new_spec.rb +1 -0
- data/spec/tags/2.4.0/core/struct/new_spec.rb +1 -0
- metadata +265 -10
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#remove_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#undef_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Struct.new raises a TypeError if object doesn't respond to to_sym
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Enumerable#any? raises an ArgumentError when any arguments provided
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#alias_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#attr is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#define_method is private
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#remove_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#undef_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Struct.new raises a TypeError if object doesn't respond to to_sym
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Enumerable#any? raises an ArgumentError when any arguments provided
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#alias_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#attr is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#define_method is private
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#remove_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#undef_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Struct.new raises a TypeError if object doesn't respond to to_sym
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Struct.new raises a TypeError if object doesn't respond to to_sym
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Enumerable#any? raises an ArgumentError when any arguments provided
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#alias_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#attr is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#define_method is private
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#remove_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#undef_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Struct.new raises a TypeError if object doesn't respond to to_sym
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Enumerable#any? raises an ArgumentError when any arguments provided
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#alias_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#attr is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#define_method is private
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#remove_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Module#undef_method is a private method
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:NilClass#dup raises a TypeError
|
@@ -0,0 +1 @@
|
|
1
|
+
fails:Struct.new raises a TypeError if object doesn't respond to to_sym
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class Dir
|
2
|
+
Backports::EXCLUDED_CHILDREN = ['.', '..'].freeze
|
3
|
+
def self.each_child(*args)
|
4
|
+
return to_enum(__method__, *args) unless block_given?
|
5
|
+
foreach(*args) { |f| yield f unless Backports::EXCLUDED_CHILDREN.include? f }
|
6
|
+
end
|
7
|
+
end unless Dir.respond_to? :each_child
|
@@ -0,0 +1,13 @@
|
|
1
|
+
if Enumerable.instance_method(:all?).arity == 0
|
2
|
+
require 'backports/tools/alias_method_chain'
|
3
|
+
require 'backports/tools/arguments'
|
4
|
+
|
5
|
+
module Enumerable
|
6
|
+
def all_with_pattern?(pattern = Backports::Undefined, &block)
|
7
|
+
return all_without_pattern?(&block) if Backports::Undefined == pattern
|
8
|
+
each_entry { |x| return false unless pattern === x }
|
9
|
+
true
|
10
|
+
end
|
11
|
+
Backports.alias_method_chain(self, :all?, :pattern)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
if Enumerable.instance_method(:any?).arity == 0
|
2
|
+
require 'backports/tools/alias_method_chain'
|
3
|
+
require 'backports/tools/arguments'
|
4
|
+
|
5
|
+
module Enumerable
|
6
|
+
def any_with_pattern?(pattern = Backports::Undefined, &block)
|
7
|
+
return any_without_pattern?(&block) if Backports::Undefined == pattern
|
8
|
+
each_entry { |x| return true if pattern === x }
|
9
|
+
false
|
10
|
+
end
|
11
|
+
Backports.alias_method_chain(self, :any?, :pattern)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# MRI specializes `any?` for Array and Hash, so redefine those too
|
16
|
+
if Array.instance_method(:any?).arity == 0
|
17
|
+
require 'backports/tools/alias_method_chain'
|
18
|
+
require 'backports/tools/arguments'
|
19
|
+
|
20
|
+
class Array
|
21
|
+
def any_with_pattern?(pattern = Backports::Undefined, &block)
|
22
|
+
return any_without_pattern?(&block) if Backports::Undefined == pattern
|
23
|
+
each_entry { |x| return true if pattern === x }
|
24
|
+
false
|
25
|
+
end
|
26
|
+
Backports.alias_method_chain(self, :any?, :pattern)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if Hash.instance_method(:any?).arity == 0
|
31
|
+
require 'backports/tools/alias_method_chain'
|
32
|
+
require 'backports/tools/arguments'
|
33
|
+
|
34
|
+
class Hash
|
35
|
+
def any_with_pattern?(pattern = Backports::Undefined, &block)
|
36
|
+
return any_without_pattern?(&block) if Backports::Undefined == pattern
|
37
|
+
each_entry { |x| return true if pattern === x }
|
38
|
+
false
|
39
|
+
end
|
40
|
+
Backports.alias_method_chain(self, :any?, :pattern)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'backports/1.8.7/enumerable/none'
|
2
|
+
|
3
|
+
if Enumerable.instance_method(:none?).arity == 0
|
4
|
+
require 'backports/tools/alias_method_chain'
|
5
|
+
require 'backports/tools/arguments'
|
6
|
+
|
7
|
+
module Enumerable
|
8
|
+
def none_with_pattern?(pattern = Backports::Undefined, &block)
|
9
|
+
return none_without_pattern?(&block) if Backports::Undefined == pattern
|
10
|
+
each_entry { |x| return false if pattern === x }
|
11
|
+
true
|
12
|
+
end
|
13
|
+
Backports.alias_method_chain(self, :none?, :pattern)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'backports/1.8.7/enumerable/one'
|
2
|
+
|
3
|
+
if Enumerable.instance_method(:one?).arity == 0
|
4
|
+
require 'backports/tools/alias_method_chain'
|
5
|
+
require 'backports/tools/arguments'
|
6
|
+
|
7
|
+
module Enumerable
|
8
|
+
def one_with_pattern?(pattern = Backports::Undefined, &block)
|
9
|
+
return one_without_pattern?(&block) if Backports::Undefined == pattern
|
10
|
+
found_one = false
|
11
|
+
each_entry do |o|
|
12
|
+
if pattern === o
|
13
|
+
return false if found_one
|
14
|
+
found_one = true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
found_one
|
18
|
+
end
|
19
|
+
Backports.alias_method_chain(self, :one?, :pattern)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Hash
|
2
|
+
def transform_keys
|
3
|
+
return to_enum(:transform_keys){ size } unless block_given?
|
4
|
+
h = {}
|
5
|
+
each do |key, value|
|
6
|
+
h[yield key] = value
|
7
|
+
end
|
8
|
+
h
|
9
|
+
end unless method_defined? :transform_keys
|
10
|
+
|
11
|
+
def transform_keys!
|
12
|
+
return enum_for(:transform_keys!) { size } unless block_given?
|
13
|
+
merge!({}) if frozen?
|
14
|
+
keys.each do |key|
|
15
|
+
self[yield(key)] = delete(key)
|
16
|
+
end
|
17
|
+
self
|
18
|
+
end unless method_defined? :transform_keys!
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Integer
|
2
|
+
require 'backports/tools/arguments'
|
3
|
+
require 'backports/2.1.0/bignum/bit_length'
|
4
|
+
require 'backports/2.1.0/fixnum/bit_length'
|
5
|
+
|
6
|
+
def self.sqrt(n)
|
7
|
+
n = Backports.coerce_to_int(n)
|
8
|
+
return Math.sqrt(n).to_i if n <= 9_999_899_999_899_999_322_536_673_279
|
9
|
+
bits_shift = n.bit_length/2 + 1
|
10
|
+
bitn_mask = root = 1 << bits_shift
|
11
|
+
while true
|
12
|
+
root ^= bitn_mask if (root * root) > n
|
13
|
+
bitn_mask >>= 1
|
14
|
+
return root if bitn_mask == 0
|
15
|
+
root |= bitn_mask
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end unless Integer.respond_to? :sqrt
|