backports 3.0.3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/.gitmodules +3 -0
- data/.travis.yml +11 -2
- data/CHANGELOG.rdoc +6 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +24 -0
- data/README.rdoc +39 -11
- data/Rakefile +98 -1
- data/default.mspec +9 -0
- data/lib/backports.rb +4 -4
- data/lib/backports/1.8.7.rb +2 -3
- data/lib/backports/1.8.7/argf.rb +2 -43
- data/lib/backports/1.8.7/argf/bytes.rb +1 -0
- data/lib/backports/1.8.7/argf/chars.rb +1 -0
- data/lib/backports/1.8.7/argf/each.rb +3 -0
- data/lib/backports/1.8.7/argf/each_byte.rb +9 -0
- data/lib/backports/1.8.7/argf/each_char.rb +35 -0
- data/lib/backports/1.8.7/argf/each_line.rb +3 -0
- data/lib/backports/1.8.7/argf/getbyte.rb +5 -0
- data/lib/backports/1.8.7/argf/lines.rb +5 -0
- data/lib/backports/1.8.7/argf/readbyte.rb +5 -0
- data/lib/backports/1.8.7/array.rb +2 -207
- data/lib/backports/1.8.7/array/collect.rb +3 -0
- data/lib/backports/1.8.7/array/combination.rb +24 -0
- data/lib/backports/1.8.7/array/cycle.rb +16 -0
- data/lib/backports/1.8.7/array/delete_if.rb +3 -0
- data/lib/backports/1.8.7/array/each.rb +3 -0
- data/lib/backports/1.8.7/array/each_index.rb +3 -0
- data/lib/backports/1.8.7/array/find_index.rb +1 -0
- data/lib/backports/1.8.7/array/flatten.rb +47 -0
- data/lib/backports/1.8.7/array/index.rb +15 -0
- data/lib/backports/1.8.7/array/map.rb +3 -0
- data/lib/backports/1.8.7/array/permutation.rb +30 -0
- data/lib/backports/1.8.7/array/pop.rb +15 -0
- data/lib/backports/1.8.7/array/product.rb +32 -0
- data/lib/backports/1.8.7/array/reject.rb +3 -0
- data/lib/backports/1.8.7/array/reverse_each.rb +3 -0
- data/lib/backports/1.8.7/array/rindex.rb +15 -0
- data/lib/backports/1.8.7/array/select.rb +3 -0
- data/lib/backports/1.8.7/array/shift.rb +13 -0
- data/lib/backports/1.8.7/array/shuffle.rb +17 -0
- data/lib/backports/1.8.7/binding.rb +3 -6
- data/lib/backports/1.8.7/binding/eval.rb +7 -0
- data/lib/backports/1.8.7/dir.rb +2 -57
- data/lib/backports/1.8.7/dir/each.rb +7 -0
- data/lib/backports/1.8.7/dir/foreach.rb +9 -0
- data/lib/backports/1.8.7/dir/mktmpdir.rb +44 -0
- data/lib/backports/1.8.7/enumerable.rb +2 -240
- data/lib/backports/1.8.7/enumerable/count.rb +17 -0
- data/lib/backports/1.8.7/enumerable/cycle.rb +24 -0
- data/lib/backports/1.8.7/enumerable/detect.rb +3 -0
- data/lib/backports/1.8.7/enumerable/drop.rb +13 -0
- data/lib/backports/1.8.7/enumerable/drop_while.rb +16 -0
- data/lib/backports/1.8.7/enumerable/each_cons.rb +4 -0
- data/lib/backports/1.8.7/enumerable/each_slice.rb +4 -0
- data/lib/backports/1.8.7/enumerable/each_with_index.rb +3 -0
- data/lib/backports/1.8.7/enumerable/entries.rb +11 -0
- data/lib/backports/1.8.7/enumerable/find.rb +3 -0
- data/lib/backports/1.8.7/enumerable/find_all.rb +3 -0
- data/lib/backports/1.8.7/enumerable/find_index.rb +21 -0
- data/lib/backports/1.8.7/enumerable/first.rb +21 -0
- data/lib/backports/1.8.7/enumerable/group_by.rb +14 -0
- data/lib/backports/1.8.7/enumerable/inject.rb +14 -0
- data/lib/backports/1.8.7/enumerable/max_by.rb +16 -0
- data/lib/backports/1.8.7/enumerable/min_by.rb +16 -0
- data/lib/backports/1.8.7/enumerable/minmax.rb +21 -0
- data/lib/backports/1.8.7/enumerable/minmax_by.rb +19 -0
- data/lib/backports/1.8.7/enumerable/none.rb +7 -0
- data/lib/backports/1.8.7/enumerable/one.rb +23 -0
- data/lib/backports/1.8.7/enumerable/partition.rb +3 -0
- data/lib/backports/1.8.7/enumerable/reduce.rb +1 -0
- data/lib/backports/1.8.7/enumerable/reject.rb +3 -0
- data/lib/backports/1.8.7/enumerable/reverse_each.rb +12 -0
- data/lib/backports/1.8.7/enumerable/select.rb +3 -0
- data/lib/backports/1.8.7/enumerable/sort_by.rb +3 -0
- data/lib/backports/1.8.7/enumerable/take.rb +9 -0
- data/lib/backports/1.8.7/enumerable/take_while.rb +14 -0
- data/lib/backports/1.8.7/enumerable/to_a.rb +12 -0
- data/lib/backports/1.8.7/enumerator.rb +2 -31
- data/lib/backports/1.8.7/enumerator/each.rb +6 -0
- data/lib/backports/1.8.7/enumerator/next.rb +15 -0
- data/lib/backports/1.8.7/enumerator/rewind.rb +13 -0
- data/lib/backports/1.8.7/enumerator/with_index.rb +14 -0
- data/lib/backports/1.8.7/env.rb +3 -3
- data/lib/backports/1.8.7/env/delete_if.rb +3 -0
- data/lib/backports/1.8.7/env/each.rb +3 -0
- data/lib/backports/1.8.7/env/each_key.rb +3 -0
- data/lib/backports/1.8.7/env/each_pair.rb +3 -0
- data/lib/backports/1.8.7/env/each_value.rb +3 -0
- data/lib/backports/1.8.7/env/reject.rb +4 -0
- data/lib/backports/1.8.7/env/select.rb +3 -0
- data/lib/backports/1.8.7/fixnum.rb +2 -10
- data/lib/backports/1.8.7/fixnum/div.rb +7 -0
- data/lib/backports/1.8.7/fixnum/fdiv.rb +7 -0
- data/lib/backports/1.8.7/float.rb +3 -4
- data/lib/backports/1.8.7/float/fdiv.rb +3 -0
- data/lib/backports/1.8.7/gc.rb +2 -10
- data/lib/backports/1.8.7/gc/stress.rb +9 -0
- data/lib/backports/1.8.7/hash.rb +2 -41
- data/lib/backports/1.8.7/hash/constructor.rb +25 -0
- data/lib/backports/1.8.7/hash/delete_if.rb +3 -0
- data/lib/backports/1.8.7/hash/each.rb +3 -0
- data/lib/backports/1.8.7/hash/each_key.rb +3 -0
- data/lib/backports/1.8.7/hash/each_pair.rb +3 -0
- data/lib/backports/1.8.7/hash/each_value.rb +3 -0
- data/lib/backports/1.8.7/hash/eql.rb +1 -0
- data/lib/backports/1.8.7/hash/hash.rb +17 -0
- data/lib/backports/1.8.7/hash/key.rb +3 -0
- data/lib/backports/1.8.7/hash/reject.rb +3 -0
- data/lib/backports/1.8.7/hash/select.rb +3 -0
- data/lib/backports/1.8.7/integer.rb +2 -23
- data/lib/backports/1.8.7/integer/downto.rb +3 -0
- data/lib/backports/1.8.7/integer/even.rb +7 -0
- data/lib/backports/1.8.7/integer/odd.rb +7 -0
- data/lib/backports/1.8.7/integer/ord.rb +7 -0
- data/lib/backports/1.8.7/integer/pred.rb +7 -0
- data/lib/backports/1.8.7/integer/times.rb +3 -0
- data/lib/backports/1.8.7/integer/upto.rb +3 -0
- data/lib/backports/1.8.7/io.rb +2 -42
- data/lib/backports/1.8.7/io/bytes.rb +1 -0
- data/lib/backports/1.8.7/io/chars.rb +1 -0
- data/lib/backports/1.8.7/io/each.rb +3 -0
- data/lib/backports/1.8.7/io/each_byte.rb +6 -0
- data/lib/backports/1.8.7/io/each_char.rb +34 -0
- data/lib/backports/1.8.7/io/each_line.rb +6 -0
- data/lib/backports/1.8.7/io/foreach.rb +7 -0
- data/lib/backports/1.8.7/io/getbyte.rb +3 -0
- data/lib/backports/1.8.7/io/lines.rb +1 -0
- data/lib/backports/1.8.7/io/readbyte.rb +3 -0
- data/lib/backports/1.8.7/kernel.rb +2 -35
- data/lib/backports/1.8.7/kernel/__method__.rb +8 -0
- data/lib/backports/1.8.7/kernel/instance_exec.rb +10 -0
- data/lib/backports/1.8.7/kernel/tap.rb +8 -0
- data/lib/backports/1.8.7/method.rb +2 -46
- data/lib/backports/1.8.7/method/name.rb +49 -0
- data/lib/backports/1.8.7/module.rb +3 -7
- data/lib/backports/1.8.7/module/class_exec.rb +1 -0
- data/lib/backports/1.8.7/module/module_exec.rb +11 -0
- data/lib/backports/1.8.7/numeric.rb +3 -3
- data/lib/backports/1.8.7/numeric/step.rb +3 -0
- data/lib/backports/1.8.7/object_space.rb +3 -5
- data/lib/backports/1.8.7/object_space/each_object.rb +5 -0
- data/lib/backports/1.8.7/proc.rb +3 -4
- data/lib/backports/1.8.7/proc/yield.rb +3 -0
- data/lib/backports/1.8.7/process.rb +3 -5
- data/lib/backports/1.8.7/process/exec.rb +3 -0
- data/lib/backports/1.8.7/range.rb +3 -4
- data/lib/backports/1.8.7/range/each.rb +3 -0
- data/lib/backports/1.8.7/range/step.rb +3 -0
- data/lib/backports/1.8.7/regexp.rb +3 -12
- data/lib/backports/1.8.7/regexp/union.rb +11 -0
- data/lib/backports/1.8.7/stop_iteration.rb +14 -0
- data/lib/backports/1.8.7/string.rb +2 -91
- data/lib/backports/1.8.7/string/bytes.rb +1 -0
- data/lib/backports/1.8.7/string/bytesize.rb +3 -0
- data/lib/backports/1.8.7/string/each.rb +3 -0
- data/lib/backports/1.8.7/string/each_byte.rb +5 -0
- data/lib/backports/1.8.7/string/each_char.rb +13 -0
- data/lib/backports/1.8.7/string/each_line.rb +5 -0
- data/lib/backports/1.8.7/string/end_with.rb +12 -0
- data/lib/backports/1.8.7/string/lines.rb +1 -0
- data/lib/backports/1.8.7/string/partition.rb +20 -0
- data/lib/backports/1.8.7/string/rpartition.rb +19 -0
- data/lib/backports/1.8.7/string/start_with.rb +12 -0
- data/lib/backports/1.8.7/string/upto.rb +15 -0
- data/lib/backports/1.8.7/struct.rb +3 -3
- data/lib/backports/1.8.7/struct/each.rb +3 -0
- data/lib/backports/1.8.7/struct/each_pair.rb +3 -0
- data/lib/backports/1.8.7/symbol.rb +3 -6
- data/lib/backports/1.8.7/symbol/to_proc.rb +8 -0
- data/lib/backports/1.8.8.rb +1 -3
- data/lib/backports/1.8.rb +1 -3
- data/lib/backports/1.9.1.rb +2 -4
- data/lib/backports/1.9.1/array.rb +3 -8
- data/lib/backports/1.9.1/array/sample.rb +19 -0
- data/lib/backports/1.9.1/array/try_convert.rb +7 -0
- data/lib/backports/1.9.1/dir.rb +3 -3
- data/lib/backports/1.9.1/dir/to_path.rb +3 -0
- data/lib/backports/1.9.1/enumerable.rb +2 -18
- data/lib/backports/1.9.1/enumerable/each_with_index.rb +14 -0
- data/lib/backports/1.9.1/enumerable/each_with_object.rb +9 -0
- data/lib/backports/1.9.1/enumerator.rb +2 -40
- data/lib/backports/1.9.1/enumerator/new.rb +40 -0
- data/lib/backports/1.9.1/enumerator/with_object.rb +6 -0
- data/lib/backports/1.9.1/env.rb +3 -3
- data/lib/backports/1.9.1/env/key.rb +5 -0
- data/lib/backports/1.9.1/file.rb +2 -43
- data/lib/backports/1.9.1/file/atime.rb +5 -0
- data/lib/backports/1.9.1/file/basename.rb +5 -0
- data/lib/backports/1.9.1/file/binary.rb +6 -0
- data/lib/backports/1.9.1/file/blockdev.rb +5 -0
- data/lib/backports/1.9.1/file/chardev.rb +5 -0
- data/lib/backports/1.9.1/file/chmod.rb +5 -0
- data/lib/backports/1.9.1/file/chown.rb +5 -0
- data/lib/backports/1.9.1/file/ctime.rb +5 -0
- data/lib/backports/1.9.1/file/delete.rb +5 -0
- data/lib/backports/1.9.1/file/directory.rb +5 -0
- data/lib/backports/1.9.1/file/dirname.rb +5 -0
- data/lib/backports/1.9.1/file/executable.rb +5 -0
- data/lib/backports/1.9.1/file/executable_real.rb +5 -0
- data/lib/backports/1.9.1/file/exist.rb +5 -0
- data/lib/backports/1.9.1/file/exists.rb +5 -0
- data/lib/backports/1.9.1/file/expand_path.rb +14 -0
- data/lib/backports/1.9.1/file/extname.rb +5 -0
- data/lib/backports/1.9.1/file/file.rb +5 -0
- data/lib/backports/1.9.1/file/ftype.rb +5 -0
- data/lib/backports/1.9.1/file/grpowned.rb +5 -0
- data/lib/backports/1.9.1/file/join.rb +5 -0
- data/lib/backports/1.9.1/file/lchmod.rb +5 -0
- data/lib/backports/1.9.1/file/lchown.rb +5 -0
- data/lib/backports/1.9.1/file/link.rb +5 -0
- data/lib/backports/1.9.1/file/lstat.rb +5 -0
- data/lib/backports/1.9.1/file/mtime.rb +5 -0
- data/lib/backports/1.9.1/file/new.rb +5 -0
- data/lib/backports/1.9.1/file/open.rb +23 -0
- data/lib/backports/1.9.1/file/owned.rb +5 -0
- data/lib/backports/1.9.1/file/pipe.rb +5 -0
- data/lib/backports/1.9.1/file/readable.rb +5 -0
- data/lib/backports/1.9.1/file/readable_real.rb +5 -0
- data/lib/backports/1.9.1/file/readlink.rb +5 -0
- data/lib/backports/1.9.1/file/rename.rb +5 -0
- data/lib/backports/1.9.1/file/setgid.rb +5 -0
- data/lib/backports/1.9.1/file/setuid.rb +5 -0
- data/lib/backports/1.9.1/file/size.rb +14 -0
- data/lib/backports/1.9.1/file/socket.rb +5 -0
- data/lib/backports/1.9.1/file/split.rb +5 -0
- data/lib/backports/1.9.1/file/stat.rb +5 -0
- data/lib/backports/1.9.1/file/sticky.rb +5 -0
- data/lib/backports/1.9.1/file/symlink.rb +6 -0
- data/lib/backports/1.9.1/file/to_path.rb +3 -0
- data/lib/backports/1.9.1/file/truncate.rb +5 -0
- data/lib/backports/1.9.1/file/unlink.rb +5 -0
- data/lib/backports/1.9.1/file/writable.rb +5 -0
- data/lib/backports/1.9.1/file/writable_real.rb +5 -0
- data/lib/backports/1.9.1/file/zero.rb +5 -0
- data/lib/backports/1.9.1/float.rb +3 -19
- data/lib/backports/1.9.1/float/round.rb +21 -0
- data/lib/backports/1.9.1/hash.rb +2 -35
- data/lib/backports/1.9.1/hash/assoc.rb +12 -0
- data/lib/backports/1.9.1/hash/default_proc.rb +14 -0
- data/lib/backports/1.9.1/hash/rassoc.rb +9 -0
- data/lib/backports/1.9.1/hash/try_convert.rb +7 -0
- data/lib/backports/1.9.1/integer.rb +2 -21
- data/lib/backports/1.9.1/integer/magnitude.rb +3 -0
- data/lib/backports/1.9.1/integer/round.rb +24 -0
- data/lib/backports/1.9.1/io.rb +2 -33
- data/lib/backports/1.9.1/io/binread.rb +10 -0
- data/lib/backports/1.9.1/io/open.rb +21 -0
- data/lib/backports/1.9.1/io/try_convert.rb +7 -0
- data/lib/backports/1.9.1/io/ungetbyte.rb +3 -0
- data/lib/backports/1.9.1/kernel.rb +2 -39
- data/lib/backports/1.9.1/kernel/__callee__.rb +7 -0
- data/lib/backports/1.9.1/kernel/define_singleton_method.rb +9 -0
- data/lib/backports/1.9.1/kernel/public_method.rb +11 -0
- data/lib/backports/1.9.1/kernel/public_send.rb +13 -0
- data/lib/backports/1.9.1/kernel/require_relative.rb +14 -0
- data/lib/backports/1.9.1/math.rb +2 -24
- data/lib/backports/1.9.1/math/log.rb +22 -0
- data/lib/backports/1.9.1/math/log2.rb +5 -0
- data/lib/backports/1.9.1/numeric.rb +3 -9
- data/lib/backports/1.9.1/numeric/round.rb +11 -0
- data/lib/backports/1.9.1/proc.rb +2 -53
- data/lib/backports/1.9.1/proc/case_compare.rb +6 -0
- data/lib/backports/1.9.1/proc/curry.rb +24 -0
- data/lib/backports/1.9.1/proc/lambda.rb +40 -0
- data/lib/backports/1.9.1/range.rb +3 -3
- data/lib/backports/1.9.1/range/cover.rb +3 -0
- data/lib/backports/1.9.1/regexp.rb +3 -8
- data/lib/backports/1.9.1/regexp/try_convert.rb +7 -0
- data/lib/backports/1.9.1/stdlib.rb +1 -1
- data/lib/backports/1.9.1/string.rb +2 -44
- data/lib/backports/1.9.1/string/ascii_only.rb +7 -0
- data/lib/backports/1.9.1/string/chr.rb +7 -0
- data/lib/backports/1.9.1/string/clear.rb +8 -0
- data/lib/backports/1.9.1/string/codepoints.rb +8 -0
- data/lib/backports/1.9.1/string/each_codepoint.rb +3 -0
- data/lib/backports/1.9.1/string/getbyte.rb +3 -0
- data/lib/backports/1.9.1/string/ord.rb +7 -0
- data/lib/backports/1.9.1/string/setbyte.rb +3 -0
- data/lib/backports/1.9.1/string/try_convert.rb +7 -0
- data/lib/backports/1.9.1/symbol.rb +2 -31
- data/lib/backports/1.9.1/symbol/capitalize.rb +7 -0
- data/lib/backports/1.9.1/symbol/casecmp.rb +8 -0
- data/lib/backports/1.9.1/symbol/comparable.rb +7 -0
- data/lib/backports/1.9.1/symbol/comparison.rb +8 -0
- data/lib/backports/1.9.1/symbol/downcase.rb +7 -0
- data/lib/backports/1.9.1/symbol/element_reference.rb +7 -0
- data/lib/backports/1.9.1/symbol/empty.rb +7 -0
- data/lib/backports/1.9.1/symbol/length.rb +7 -0
- data/lib/backports/1.9.1/symbol/match.rb +9 -0
- data/lib/backports/1.9.1/symbol/next.rb +1 -0
- data/lib/backports/1.9.1/symbol/size.rb +7 -0
- data/lib/backports/1.9.1/symbol/succ.rb +8 -0
- data/lib/backports/1.9.1/symbol/swapcase.rb +7 -0
- data/lib/backports/1.9.1/symbol/upcase.rb +7 -0
- data/lib/backports/1.9.2.rb +2 -4
- data/lib/backports/1.9.2/array.rb +2 -109
- data/lib/backports/1.9.2/array/keep_if.rb +8 -0
- data/lib/backports/1.9.2/array/product.rb +26 -0
- data/lib/backports/1.9.2/array/repeated_combination.rb +25 -0
- data/lib/backports/1.9.2/array/repeated_permutation.rb +26 -0
- data/lib/backports/1.9.2/array/rotate.rb +17 -0
- data/lib/backports/1.9.2/array/select.rb +8 -0
- data/lib/backports/1.9.2/array/sort_by.rb +9 -0
- data/lib/backports/1.9.2/array/uniq.rb +29 -0
- data/lib/backports/1.9.2/complex.rb +3 -6
- data/lib/backports/1.9.2/complex/to_r.rb +10 -0
- data/lib/backports/1.9.2/dir.rb +3 -5
- data/lib/backports/1.9.2/dir/home.rb +5 -0
- data/lib/backports/1.9.2/enumerable.rb +2 -73
- data/lib/backports/1.9.2/enumerable/chunk.rb +39 -0
- data/lib/backports/1.9.2/enumerable/collect_concat.rb +1 -0
- data/lib/backports/1.9.2/enumerable/each_entry.rb +11 -0
- data/lib/backports/1.9.2/enumerable/flat_map.rb +11 -0
- data/lib/backports/1.9.2/enumerable/slice_before.rb +30 -0
- data/lib/backports/1.9.2/float.rb +3 -4
- data/lib/backports/1.9.2/float/infinity.rb +3 -0
- data/lib/backports/1.9.2/float/nan.rb +3 -0
- data/lib/backports/1.9.2/hash.rb +2 -10
- data/lib/backports/1.9.2/hash/keep_if.rb +8 -0
- data/lib/backports/1.9.2/hash/select.rb +9 -0
- data/lib/backports/1.9.2/kernel.rb +3 -5
- data/lib/backports/1.9.2/kernel/singleton_class.rb +7 -0
- data/lib/backports/1.9.2/random.rb +1 -1
- data/lib/backports/1.9.2/stdlib.rb +1 -1
- data/lib/backports/1.9.2/stdlib/matrix.rb +9 -8
- data/lib/backports/1.9.2/stdlib/set.rb +1 -1
- data/lib/backports/1.9.3.rb +2 -4
- data/lib/backports/1.9.3/file.rb +3 -14
- data/lib/backports/1.9.3/file/null.rb +16 -0
- data/lib/backports/1.9.3/io.rb +2 -31
- data/lib/backports/1.9.3/io/advise.rb +24 -0
- data/lib/backports/1.9.3/io/binwrite.rb +7 -0
- data/lib/backports/1.9.3/io/write.rb +7 -0
- data/lib/backports/1.9.3/string.rb +2 -38
- data/lib/backports/1.9.3/string/byteslice.rb +36 -0
- data/lib/backports/1.9.3/string/prepend.rb +10 -0
- data/lib/backports/1.9.rb +1 -3
- data/lib/backports/2.0.0.rb +2 -4
- data/lib/backports/2.0.0/array.rb +2 -29
- data/lib/backports/2.0.0/array/bsearch.rb +32 -0
- data/lib/backports/2.0.0/enumerable.rb +2 -11
- data/lib/backports/2.0.0/enumerable/lazy.rb +216 -0
- data/lib/backports/2.0.0/enumerator.rb +3 -0
- data/lib/backports/2.0.0/enumerator/lazy.rb +1 -203
- data/lib/backports/2.0.0/env.rb +3 -0
- data/lib/backports/2.0.0/env/to_h.rb +5 -0
- data/lib/backports/2.0.0/hash.rb +2 -18
- data/lib/backports/2.0.0/hash/default_proc.rb +16 -0
- data/lib/backports/2.0.0/hash/to_h.rb +7 -0
- data/lib/backports/2.0.0/nil.rb +3 -0
- data/lib/backports/2.0.0/nil/to_h.rb +7 -0
- data/lib/backports/2.0.0/range.rb +2 -48
- data/lib/backports/2.0.0/range/bsearch.rb +49 -0
- data/lib/backports/2.0.0/stdlib/abbrev.rb +1 -0
- data/lib/backports/2.0.0/stdlib/fake_stdlib_lib.rb +1 -0
- data/lib/backports/2.0.0/stdlib/ostruct.rb +1 -1
- data/lib/backports/2.0.0/struct.rb +3 -7
- data/lib/backports/2.0.0/struct/to_h.rb +9 -0
- data/lib/backports/2.0.rb +1 -3
- data/lib/backports/basic_object.rb +29 -29
- data/lib/backports/{1.9.2 → extra}/random/MT19937.rb +2 -2
- data/lib/backports/{1.9.2 → extra}/random/bits_and_bytes.rb +1 -1
- data/lib/backports/{1.9.2 → extra}/random/implementation.rb +1 -1
- data/lib/backports/extra/random/load.rb +17 -0
- data/lib/backports/force/array_map.rb +1 -1
- data/lib/backports/force/enumerable_map.rb +1 -1
- data/lib/backports/force/hash_select.rb +1 -1
- data/lib/backports/force/string_size.rb +1 -1
- data/lib/backports/rails.rb +2 -2
- data/lib/backports/rails/enumerable.rb +1 -1
- data/lib/backports/rails/hash.rb +1 -1
- data/lib/backports/rails/kernel.rb +1 -1
- data/lib/backports/rails/module.rb +1 -1
- data/lib/backports/rails/string.rb +6 -6
- data/lib/backports/tools.rb +74 -64
- data/lib/backports/version.rb +1 -1
- data/set_version/1.8.7.rb +1 -0
- data/set_version/1.9.1.rb +1 -0
- data/set_version/1.9.2.rb +1 -0
- data/set_version/1.9.3.rb +1 -0
- data/set_version/2.0.0.rb +1 -0
- data/set_version/setter.rb +14 -0
- data/tags/1.8.6/core/array/rotate_spec.rb +2 -0
- data/tags/1.8.6/core/array/uniq_spec.rb +3 -0
- data/tags/1.8.6/core/complex/to_r_spec.rb +3 -0
- data/tags/1.8.6/core/enumerable/each_entry_spec.rb +1 -0
- data/tags/1.8.6/core/enumerator/next_spec.rb +1 -0
- data/tags/1.8.6/core/env/to_h_spec.rb +2 -0
- data/tags/1.8.6/core/file/join_spec.rb +3 -0
- data/tags/1.8.6/core/file/lchmod_spec.rb +2 -0
- data/tags/1.8.6/core/file/new_spec.rb +2 -0
- data/tags/1.8.6/core/file/open_spec.rb +10 -0
- data/tags/1.8.6/core/file/to_path_spec.rb +1 -0
- data/tags/1.8.6/core/fixnum/fdiv_spec.rb +1 -0
- data/tags/1.8.6/core/gc/stress_spec.rb +2 -0
- data/tags/1.8.6/core/hash/assoc_spec.rb +1 -0
- data/tags/1.8.6/core/hash/default_proc_spec.rb +2 -0
- data/tags/1.8.6/core/hash/eql_spec.rb +3 -0
- data/tags/1.8.6/core/hash/hash_spec.rb +3 -0
- data/tags/1.8.6/core/hash/keep_if_spec.rb +1 -0
- data/tags/1.8.6/core/hash/select_spec.rb +1 -0
- data/tags/1.8.6/core/integer/round_spec.rb +1 -0
- data/tags/1.8.6/core/io/binread_spec.rb +7 -0
- data/tags/1.8.6/core/io/chars_spec.rb +1 -0
- data/tags/1.8.6/core/io/each_char_spec.rb +1 -0
- data/tags/1.8.6/core/io/lines_spec.rb +1 -0
- data/tags/1.8.6/core/io/open_spec.rb +24 -0
- data/tags/1.8.6/core/io/ungetbyte_spec.rb +4 -0
- data/tags/1.8.6/core/io/write_spec.rb +3 -0
- data/tags/1.8.6/core/kernel/__callee___spec.rb +5 -0
- data/tags/1.8.6/core/kernel/__method___spec.rb +1 -0
- data/tags/1.8.6/core/kernel/define_singleton_method_spec.rb +2 -0
- data/tags/1.8.6/core/kernel/public_method_spec.rb +2 -0
- data/tags/1.8.6/core/math/log2_spec.rb +4 -0
- data/tags/1.8.6/core/math/log_spec.rb +3 -0
- data/tags/1.8.6/core/module/class_exec_spec.rb +2 -0
- data/tags/1.8.6/core/module/module_exec_spec.rb +2 -0
- data/tags/1.8.6/core/numeric/step_spec.rb +12 -0
- data/tags/1.8.6/core/proc/curry_spec.rb +4 -0
- data/tags/1.8.6/core/range/step_spec.rb +12 -0
- data/tags/1.8.6/core/string/getbyte_spec.rb +6 -0
- data/tags/1.8.6/core/string/partition_spec.rb +1 -0
- data/tags/1.8.6/core/string/prepend_spec.rb +1 -0
- data/tags/1.8.6/core/string/rpartition_spec.rb +1 -0
- data/tags/1.8.6/core/string/setbyte_spec.rb +5 -0
- data/tags/1.8.6/core/string/upto_spec.rb +1 -0
- data/tags/1.8.6/core/symbol/capitalize_spec.rb +3 -0
- data/tags/1.8.6/core/symbol/comparison_spec.rb +1 -0
- data/tags/1.8.6/core/symbol/downcase_spec.rb +2 -0
- data/tags/1.8.6/core/symbol/element_reference_spec.rb +2 -0
- data/tags/1.8.6/core/symbol/empty_spec.rb +1 -0
- data/tags/1.8.6/core/symbol/match_spec.rb +2 -0
- data/tags/1.8.6/core/symbol/swapcase_spec.rb +2 -0
- data/tags/1.8.6/core/symbol/upcase_spec.rb +1 -0
- data/tags/1.8.7/core/array/rotate_spec.rb +2 -0
- data/tags/1.8.7/core/array/uniq_spec.rb +3 -0
- data/tags/1.8.7/core/complex/to_r_spec.rb +3 -0
- data/tags/1.8.7/core/env/to_h_spec.rb +2 -0
- data/tags/1.8.7/core/file/lchmod_spec.rb +2 -0
- data/tags/1.8.7/core/file/new_spec.rb +1 -0
- data/tags/1.8.7/core/file/open_spec.rb +1 -0
- data/tags/1.8.7/core/file/readlink_spec.rb +6 -0
- data/tags/1.8.7/core/file/to_path_spec.rb +1 -0
- data/tags/1.8.7/core/hash/assoc_spec.rb +1 -0
- data/tags/1.8.7/core/hash/default_proc_spec.rb +2 -0
- data/tags/1.8.7/core/hash/keep_if_spec.rb +1 -0
- data/tags/1.8.7/core/hash/rassoc_spec.rb +1 -0
- data/tags/1.8.7/core/hash/select_spec.rb +1 -0
- data/tags/1.8.7/core/integer/round_spec.rb +1 -0
- data/tags/1.8.7/core/io/binread_spec.rb +7 -0
- data/tags/1.8.7/core/io/open_spec.rb +25 -0
- data/tags/1.8.7/core/io/ungetbyte_spec.rb +4 -0
- data/tags/1.8.7/core/io/write_spec.rb +3 -0
- data/tags/1.8.7/core/kernel/__callee___spec.rb +5 -0
- data/tags/1.8.7/core/kernel/define_singleton_method_spec.rb +2 -0
- data/tags/1.8.7/core/kernel/public_method_spec.rb +1 -0
- data/tags/1.8.7/core/math/log2_spec.rb +4 -0
- data/tags/1.8.7/core/math/log_spec.rb +3 -0
- data/tags/1.8.7/core/proc/curry_spec.rb +3 -0
- data/tags/1.8.7/core/string/getbyte_spec.rb +5 -0
- data/tags/1.8.7/core/string/prepend_spec.rb +1 -0
- data/tags/1.8.7/core/string/setbyte_spec.rb +5 -0
- data/tags/1.8.7/core/symbol/capitalize_spec.rb +3 -0
- data/tags/1.8.7/core/symbol/comparison_spec.rb +1 -0
- data/tags/1.8.7/core/symbol/downcase_spec.rb +2 -0
- data/tags/1.8.7/core/symbol/element_reference_spec.rb +2 -0
- data/tags/1.8.7/core/symbol/empty_spec.rb +1 -0
- data/tags/1.8.7/core/symbol/match_spec.rb +2 -0
- data/tags/1.8.7/core/symbol/swapcase_spec.rb +2 -0
- data/tags/1.8.7/core/symbol/upcase_spec.rb +1 -0
- data/tags/1.9.1/core/array/rotate_spec.rb +1 -0
- data/tags/1.9.1/core/env/to_h_spec.rb +2 -0
- data/tags/1.9.1/core/hash/default_proc_spec.rb +1 -0
- data/tags/1.9.1/core/io/write_spec.rb +2 -0
- data/tags/1.9.2/core/io/write_spec.rb +2 -0
- data/test/README +1 -1
- data/test/_backport_guards_test.rb +140 -0
- data/test/{test_lazy.rb → lazy_test.rb} +25 -20
- data/test/{test_socket_interaction.rb → socket_interaction_test.rb} +3 -3
- data/test/test_helper.rb +0 -4
- metadata +392 -16
- data/lib/backports/1.9.2/match_data.rb +0 -3
- data/lib/backports/1.9.2/random/load.rb +0 -16
- data/lib/backports/2.0.0/nil_class.rb +0 -5
- data/test/std_lib_loading_test.rb +0 -57
- data/test/test__me_first.rb +0 -51
@@ -0,0 +1,15 @@
|
|
1
|
+
unless ([1].rindex{true} rescue false)
|
2
|
+
class Array
|
3
|
+
require 'backports/tools'
|
4
|
+
require 'enumerator'
|
5
|
+
|
6
|
+
def rindex_with_block(*arg)
|
7
|
+
return to_enum(:rindex) if !block_given? && arg.empty?
|
8
|
+
return rindex_without_block(*arg) unless block_given? && arg.empty?
|
9
|
+
i = 0
|
10
|
+
reverse_each{|o| i += 1; return size - i if yield o}
|
11
|
+
return nil
|
12
|
+
end
|
13
|
+
Backports.alias_method_chain self, :rindex, :block
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
unless ([1].shift(1) rescue false)
|
2
|
+
class Array
|
3
|
+
require 'backports/tools'
|
4
|
+
|
5
|
+
def shift_with_optional_argument(n = Backports::Undefined)
|
6
|
+
return shift_without_optional_argument if n == Backports::Undefined
|
7
|
+
n = Backports.coerce_to_int(n)
|
8
|
+
raise ArgumentError, "negative array size" if n < 0
|
9
|
+
slice!(0, n)
|
10
|
+
end
|
11
|
+
Backports.alias_method_chain self, :shift, :optional_argument
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
unless Array.method_defined? :shuffle
|
2
|
+
class Array
|
3
|
+
def shuffle
|
4
|
+
dup.shuffle!
|
5
|
+
end
|
6
|
+
|
7
|
+
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
|
8
|
+
def shuffle!
|
9
|
+
raise TypeError, "can't modify frozen array" if frozen?
|
10
|
+
size.times do |i|
|
11
|
+
r = i + Kernel.rand(size - i)
|
12
|
+
self[i], self[r] = self[r], self[i]
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Kernel.eval(expr, self, *arg)
|
5
|
-
end unless method_defined? :eval
|
6
|
-
end
|
1
|
+
require 'backports/tools'
|
2
|
+
|
3
|
+
Backports.require_relative_dir
|
data/lib/backports/1.8.7/dir.rb
CHANGED
@@ -1,58 +1,3 @@
|
|
1
|
-
|
2
|
-
begin
|
3
|
-
Backports.make_block_optional self, :each, :test_on => Dir.new('.')
|
4
|
-
rescue # We may not be able to read the current directory, issue #58
|
5
|
-
Backports.make_block_optional self, :each, :force => true if RUBY_VERSION < '1.8.7'
|
6
|
-
end
|
7
|
-
|
8
|
-
class << self
|
9
|
-
begin
|
10
|
-
Backports.make_block_optional self, :foreach, :test_on => Dir, :arg => '.'
|
11
|
-
rescue # We may not be able to read the current directory, issue #58
|
12
|
-
Backports.make_block_optional self, :foreach, :force => true if RUBY_VERSION < '1.8.7'
|
13
|
-
end
|
14
|
-
|
15
|
-
def mktmpdir(prefix_suffix=nil, tmpdir=nil)
|
16
|
-
raise NoMethodError, "undefined method `mktmpdir' for Dir:Class; you must require 'tmpdir'" unless respond_to? :tmpdir
|
17
|
-
|
18
|
-
case prefix_suffix
|
19
|
-
when nil
|
20
|
-
prefix = "d"
|
21
|
-
suffix = ""
|
22
|
-
when String
|
23
|
-
prefix = prefix_suffix
|
24
|
-
suffix = ""
|
25
|
-
when Array
|
26
|
-
prefix = prefix_suffix[0]
|
27
|
-
suffix = prefix_suffix[1]
|
28
|
-
else
|
29
|
-
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
|
30
|
-
end
|
31
|
-
tmpdir ||= Dir.tmpdir
|
32
|
-
t = Time.now.strftime("%Y%m%d")
|
33
|
-
n = nil
|
34
|
-
begin
|
35
|
-
path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{Kernel.rand(0x100000000).to_s(36)}"
|
36
|
-
path << "-#{n}" if n
|
37
|
-
path << suffix
|
38
|
-
Dir.mkdir(path, 0700)
|
39
|
-
rescue Errno::EEXIST
|
40
|
-
n ||= 0
|
41
|
-
n += 1
|
42
|
-
retry
|
43
|
-
end
|
44
|
-
|
45
|
-
if block_given?
|
46
|
-
begin
|
47
|
-
yield path
|
48
|
-
ensure
|
49
|
-
FileUtils.remove_entry_secure path
|
50
|
-
end
|
51
|
-
else
|
52
|
-
path
|
53
|
-
end
|
54
|
-
end unless method_defined? :mktmpdir
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
1
|
+
require 'backports/tools'
|
58
2
|
|
3
|
+
Backports.require_relative_dir
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'backports/tools'
|
2
|
+
|
3
|
+
class << Dir
|
4
|
+
begin
|
5
|
+
Backports.make_block_optional self, :foreach, :test_on => Dir, :arg => '.'
|
6
|
+
rescue # We may not be able to read the current directory, issue #58
|
7
|
+
Backports.make_block_optional self, :foreach, :force => true if RUBY_VERSION < '1.8.7'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
unless Dir.method_defined? :mktmpdir
|
2
|
+
class Dir
|
3
|
+
def mktmpdir(prefix_suffix=nil, tmpdir=nil)
|
4
|
+
raise NoMethodError, "undefined method `mktmpdir' for Dir:Class; you must require 'tmpdir'" unless respond_to? :tmpdir
|
5
|
+
|
6
|
+
case prefix_suffix
|
7
|
+
when nil
|
8
|
+
prefix = "d"
|
9
|
+
suffix = ""
|
10
|
+
when String
|
11
|
+
prefix = prefix_suffix
|
12
|
+
suffix = ""
|
13
|
+
when Array
|
14
|
+
prefix = prefix_suffix[0]
|
15
|
+
suffix = prefix_suffix[1]
|
16
|
+
else
|
17
|
+
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
|
18
|
+
end
|
19
|
+
tmpdir ||= Dir.tmpdir
|
20
|
+
t = Time.now.strftime("%Y%m%d")
|
21
|
+
n = nil
|
22
|
+
begin
|
23
|
+
path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{Kernel.rand(0x100000000).to_s(36)}"
|
24
|
+
path << "-#{n}" if n
|
25
|
+
path << suffix
|
26
|
+
Dir.mkdir(path, 0700)
|
27
|
+
rescue Errno::EEXIST
|
28
|
+
n ||= 0
|
29
|
+
n += 1
|
30
|
+
retry
|
31
|
+
end
|
32
|
+
|
33
|
+
if block_given?
|
34
|
+
begin
|
35
|
+
yield path
|
36
|
+
ensure
|
37
|
+
FileUtils.remove_entry_secure path
|
38
|
+
end
|
39
|
+
else
|
40
|
+
path
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,241 +1,3 @@
|
|
1
|
-
require '
|
2
|
-
module Enumerable
|
3
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
4
|
-
def count(item = Backports::Undefined)
|
5
|
-
seq = 0
|
6
|
-
if item != Backports::Undefined
|
7
|
-
each { |o| seq += 1 if item == o }
|
8
|
-
elsif block_given?
|
9
|
-
each { |o| seq += 1 if yield(o) }
|
10
|
-
else
|
11
|
-
each { seq += 1 }
|
12
|
-
end
|
13
|
-
seq
|
14
|
-
end unless method_defined? :count
|
1
|
+
require 'backports/tools'
|
15
2
|
|
16
|
-
|
17
|
-
def cycle(n = nil)
|
18
|
-
return to_enum(:cycle, n) unless block_given?
|
19
|
-
n = n && Backports.coerce_to_int(n)
|
20
|
-
if n == nil || n >= 1
|
21
|
-
cache = []
|
22
|
-
each do |elem|
|
23
|
-
cache << elem
|
24
|
-
yield elem
|
25
|
-
end
|
26
|
-
if n
|
27
|
-
(n-1).times { cache.each{|e| yield e } }
|
28
|
-
else
|
29
|
-
loop { cache.each{|e| yield e } }
|
30
|
-
end unless cache.empty?
|
31
|
-
end
|
32
|
-
nil
|
33
|
-
end unless method_defined? :cycle
|
34
|
-
|
35
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
36
|
-
Backports.make_block_optional self, :each_cons, :each_slice, :test_on => 1..2, :arg => 1
|
37
|
-
|
38
|
-
Backports.make_block_optional self, :detect, :find, :find_all, :select, :sort_by, :partition, :reject, :test_on => 1..2
|
39
|
-
|
40
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
41
|
-
def drop(n)
|
42
|
-
n = Backports.coerce_to_int(n)
|
43
|
-
raise ArgumentError, "attempt to drop negative size" if n < 0
|
44
|
-
ary = to_a
|
45
|
-
return [] if n > ary.size
|
46
|
-
ary[n...ary.size]
|
47
|
-
end unless method_defined? :drop
|
48
|
-
|
49
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
50
|
-
def drop_while
|
51
|
-
return to_enum(:drop_while) unless block_given?
|
52
|
-
ary = []
|
53
|
-
dropping = true
|
54
|
-
each do |obj|
|
55
|
-
ary << obj unless dropping &&= yield(obj)
|
56
|
-
end
|
57
|
-
ary
|
58
|
-
end unless method_defined? :drop_while
|
59
|
-
|
60
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
61
|
-
def find_index(obj = Backports::Undefined)
|
62
|
-
if obj != Backports::Undefined
|
63
|
-
each_with_index do |element, i|
|
64
|
-
return i if element == obj
|
65
|
-
end
|
66
|
-
elsif block_given?
|
67
|
-
each_with_index do |element, i|
|
68
|
-
return i if yield element
|
69
|
-
end
|
70
|
-
else
|
71
|
-
return to_enum(:find_index)
|
72
|
-
end
|
73
|
-
nil
|
74
|
-
end unless method_defined? :find_index
|
75
|
-
|
76
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
77
|
-
def first(n = Backports::Undefined)
|
78
|
-
return take(n) unless n == Backports::Undefined
|
79
|
-
each{|obj| return obj}
|
80
|
-
nil
|
81
|
-
end unless method_defined? :first
|
82
|
-
|
83
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
84
|
-
def group_by
|
85
|
-
return to_enum(:group_by) unless block_given?
|
86
|
-
{}.tap do |result|
|
87
|
-
each do |o|
|
88
|
-
result.fetch(yield(o)){|key| result[key] = []} << o
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end unless method_defined? :group_by
|
92
|
-
|
93
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
94
|
-
unless ((1..2).inject(:+) rescue false)
|
95
|
-
def inject_with_symbol(*args, &block)
|
96
|
-
return inject_without_symbol(*args, &block) if block_given? && args.size <= 1
|
97
|
-
method = args.pop
|
98
|
-
inject_without_symbol(*args) {|memo, obj| memo.send(method, obj)}
|
99
|
-
end
|
100
|
-
Backports.alias_method_chain self, :inject, :symbol
|
101
|
-
end
|
102
|
-
|
103
|
-
MOST_EXTREME_OBJECT_EVER = Object.new # :nodoc:
|
104
|
-
class << MOST_EXTREME_OBJECT_EVER
|
105
|
-
def < (whatever)
|
106
|
-
true
|
107
|
-
end
|
108
|
-
|
109
|
-
def > (whatever)
|
110
|
-
true
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
115
|
-
def max_by
|
116
|
-
return to_enum(:max_by) unless block_given?
|
117
|
-
max_object, max_result = nil, MOST_EXTREME_OBJECT_EVER
|
118
|
-
each do |object|
|
119
|
-
result = yield object
|
120
|
-
max_object, max_result = object, result if max_result < result
|
121
|
-
end
|
122
|
-
max_object
|
123
|
-
end unless method_defined? :max_by
|
124
|
-
|
125
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
126
|
-
def min_by
|
127
|
-
return to_enum(:min_by) unless block_given?
|
128
|
-
min_object, min_result = nil, MOST_EXTREME_OBJECT_EVER
|
129
|
-
each do |object|
|
130
|
-
result = yield object
|
131
|
-
min_object, min_result = object, result if min_result > result
|
132
|
-
end
|
133
|
-
min_object
|
134
|
-
end unless method_defined? :min_by
|
135
|
-
|
136
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
137
|
-
def minmax
|
138
|
-
return minmax{|a,b| a <=> b} unless block_given?
|
139
|
-
first_time = true
|
140
|
-
min, max = nil
|
141
|
-
each do |object|
|
142
|
-
if first_time
|
143
|
-
min = max = object
|
144
|
-
first_time = false
|
145
|
-
else
|
146
|
-
min = object if Backports.coerce_to_comparison(min, object, yield(min, object)) > 0
|
147
|
-
max = object if Backports.coerce_to_comparison(max, object, yield(max, object)) < 0
|
148
|
-
end
|
149
|
-
end
|
150
|
-
[min, max]
|
151
|
-
end unless method_defined? :minmax
|
152
|
-
|
153
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
154
|
-
def minmax_by
|
155
|
-
return to_enum(:minmax_by) unless block_given?
|
156
|
-
min_object, min_result = nil, MOST_EXTREME_OBJECT_EVER
|
157
|
-
max_object, max_result = nil, MOST_EXTREME_OBJECT_EVER
|
158
|
-
each do |object|
|
159
|
-
result = yield object
|
160
|
-
min_object, min_result = object, result if min_result > result
|
161
|
-
max_object, max_result = object, result if max_result < result
|
162
|
-
end
|
163
|
-
[min_object, max_object]
|
164
|
-
end unless method_defined? :minmax_by
|
165
|
-
|
166
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
167
|
-
def none?(&block)
|
168
|
-
!any?(&block)
|
169
|
-
end unless method_defined? :none?
|
170
|
-
|
171
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
172
|
-
def one?
|
173
|
-
found_one = false
|
174
|
-
if block_given?
|
175
|
-
each do |o|
|
176
|
-
if yield(o)
|
177
|
-
return false if found_one
|
178
|
-
found_one = true
|
179
|
-
end
|
180
|
-
end
|
181
|
-
else
|
182
|
-
each do |o|
|
183
|
-
if o
|
184
|
-
return false if found_one
|
185
|
-
found_one = true
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
found_one
|
190
|
-
end unless method_defined? :one?
|
191
|
-
|
192
|
-
Backports.alias_method self, :reduce, :inject
|
193
|
-
|
194
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
195
|
-
def reverse_each
|
196
|
-
return to_enum(:reverse_each) unless block_given?
|
197
|
-
# There is no other way then to convert to an array first... see 1.9's source.
|
198
|
-
to_a.reverse_each{|e| yield e}
|
199
|
-
self
|
200
|
-
end unless method_defined? :reverse_each
|
201
|
-
|
202
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
203
|
-
def take(n)
|
204
|
-
n = Backports.coerce_to_int(n)
|
205
|
-
raise ArgumentError, "attempt to take negative size: #{n}" if n < 0
|
206
|
-
[].tap do |array|
|
207
|
-
each do |elem|
|
208
|
-
array << elem
|
209
|
-
break if array.size >= n
|
210
|
-
end unless n <= 0
|
211
|
-
end
|
212
|
-
end unless method_defined? :take
|
213
|
-
|
214
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
215
|
-
def take_while
|
216
|
-
return to_enum(:take_while) unless block_given?
|
217
|
-
inject([]) do |array, elem|
|
218
|
-
return array unless yield elem
|
219
|
-
array << elem
|
220
|
-
end
|
221
|
-
end unless method_defined? :take_while
|
222
|
-
|
223
|
-
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
224
|
-
if instance_method(:to_a).arity.zero?
|
225
|
-
def to_a_with_optional_arguments(*args)
|
226
|
-
return to_a_without_optional_arguments if args.empty?
|
227
|
-
to_enum(:each, *args).to_a
|
228
|
-
end
|
229
|
-
Backports.alias_method_chain self, :to_a, :optional_arguments
|
230
|
-
end
|
231
|
-
|
232
|
-
# alias_method gives a warning, so instead copy-paste:
|
233
|
-
if instance_method(:entries).arity.zero?
|
234
|
-
def entries_with_optional_arguments(*args)
|
235
|
-
return entries_without_optional_arguments if args.empty?
|
236
|
-
to_enum(:each, *args).entries
|
237
|
-
end
|
238
|
-
Backports.alias_method_chain self, :entries, :optional_arguments
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|
3
|
+
Backports.require_relative_dir
|