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
@@ -1 +1 @@
|
|
1
|
-
autoload :Random,
|
1
|
+
autoload :Random, "backports/extra/random/load"
|
@@ -1 +1 @@
|
|
1
|
-
Backports::StdLib.extend_relative
|
1
|
+
Backports::StdLib.extend_relative
|
@@ -14,7 +14,6 @@
|
|
14
14
|
require "e2mmap.rb"
|
15
15
|
|
16
16
|
module ExceptionForMatrix # :nodoc:
|
17
|
-
extend Exception2MessageMapper
|
18
17
|
def_e2message(TypeError, "wrong argument type %s (expected %s)")
|
19
18
|
def_e2message(ArgumentError, "Wrong # of arguments(%d for %d)")
|
20
19
|
|
@@ -118,6 +117,7 @@ end
|
|
118
117
|
# * #to_s
|
119
118
|
# * #inspect
|
120
119
|
#
|
120
|
+
Backports.suppress_verbose_warnings do
|
121
121
|
class Matrix
|
122
122
|
include Enumerable
|
123
123
|
include ExceptionForMatrix
|
@@ -186,7 +186,7 @@ class Matrix
|
|
186
186
|
row_size = CoercionHelper.coerce_to_int(row_size)
|
187
187
|
column_size = CoercionHelper.coerce_to_int(column_size)
|
188
188
|
raise ArgumentError if row_size < 0 || column_size < 0
|
189
|
-
return to_enum
|
189
|
+
return to_enum(:build, row_size, column_size) unless block_given?
|
190
190
|
rows = Array.new(row_size) do |i|
|
191
191
|
Array.new(column_size) do |j|
|
192
192
|
yield i, j
|
@@ -401,7 +401,7 @@ class Matrix
|
|
401
401
|
# Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3]
|
402
402
|
#
|
403
403
|
def each(which = :all) # :yield: e
|
404
|
-
return to_enum
|
404
|
+
return to_enum(:each, which) unless block_given?
|
405
405
|
last = column_size - 1
|
406
406
|
case which
|
407
407
|
when :all
|
@@ -462,7 +462,7 @@ class Matrix
|
|
462
462
|
# # 4 at 1, 1
|
463
463
|
#
|
464
464
|
def each_with_index(which = :all) # :yield: e, row, column
|
465
|
-
return to_enum
|
465
|
+
return to_enum(:each_with_index, which) unless block_given?
|
466
466
|
last = column_size - 1
|
467
467
|
case which
|
468
468
|
when :all
|
@@ -527,7 +527,7 @@ class Matrix
|
|
527
527
|
def index(*args)
|
528
528
|
raise ArgumentError, "wrong number of arguments(#{args.size} for 0-2)" if args.size > 2
|
529
529
|
which = (args.size == 2 || SELECTORS.include?(args.last)) ? args.pop : :all
|
530
|
-
return to_enum
|
530
|
+
return to_enum(:find_index, which, *args) unless block_given? || args.size == 1
|
531
531
|
if args.size == 1
|
532
532
|
value = args.first
|
533
533
|
each_with_index(which) do |e, row_index, col_index|
|
@@ -809,7 +809,7 @@ class Matrix
|
|
809
809
|
rows = @rows.collect {|row|
|
810
810
|
row.collect {|e| e * m }
|
811
811
|
}
|
812
|
-
return new_matrix
|
812
|
+
return new_matrix(rows, column_size)
|
813
813
|
when Vector
|
814
814
|
m = self.class.column_vector(m)
|
815
815
|
r = self * m
|
@@ -824,7 +824,7 @@ class Matrix
|
|
824
824
|
end
|
825
825
|
}
|
826
826
|
}
|
827
|
-
return new_matrix
|
827
|
+
return new_matrix(rows, m.column_size)
|
828
828
|
else
|
829
829
|
return apply_through_coercion(m, __method__)
|
830
830
|
end
|
@@ -896,7 +896,7 @@ class Matrix
|
|
896
896
|
rows = @rows.collect {|row|
|
897
897
|
row.collect {|e| e / other }
|
898
898
|
}
|
899
|
-
return new_matrix
|
899
|
+
return new_matrix(rows, column_size)
|
900
900
|
when Matrix
|
901
901
|
return self * other.inverse
|
902
902
|
else
|
@@ -1868,3 +1868,4 @@ class Vector
|
|
1868
1868
|
"Vector" + @elements.inspect
|
1869
1869
|
end
|
1870
1870
|
end
|
1871
|
+
end
|
data/lib/backports/1.9.3.rb
CHANGED
data/lib/backports/1.9.3/file.rb
CHANGED
@@ -1,14 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
NULL = case platform
|
5
|
-
when /mswin|mingw/i
|
6
|
-
'NUL'
|
7
|
-
when /amiga/i
|
8
|
-
'NIL:'
|
9
|
-
when /openvms/i
|
10
|
-
'NL:'
|
11
|
-
else
|
12
|
-
'/dev/null'
|
13
|
-
end unless const_defined?(:NULL)
|
14
|
-
end
|
1
|
+
require 'backports/tools'
|
2
|
+
|
3
|
+
Backports.require_relative_dir
|
@@ -0,0 +1,16 @@
|
|
1
|
+
unless File.const_defined? :NULL
|
2
|
+
module File::Constants
|
3
|
+
platform = RUBY_PLATFORM
|
4
|
+
platform = RbConfig::CONFIG['host_os'] if platform == 'java'
|
5
|
+
NULL = case platform
|
6
|
+
when /mswin|mingw/i
|
7
|
+
'NUL'
|
8
|
+
when /amiga/i
|
9
|
+
'NIL:'
|
10
|
+
when /openvms/i
|
11
|
+
'NL:'
|
12
|
+
else
|
13
|
+
'/dev/null'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/backports/1.9.3/io.rb
CHANGED
@@ -1,32 +1,3 @@
|
|
1
|
-
|
2
|
-
# Standard in Ruby 1.9.3 See official documentation[http://ruby-doc.org/core-1.9.3/IO.html#method-i-advise]
|
3
|
-
# We're only for a platform not implementing advise, so we return nil.
|
4
|
-
def advise(advice, offset=0, len=0)
|
5
|
-
case advice
|
6
|
-
when :normal,
|
7
|
-
:sequential,
|
8
|
-
:random,
|
9
|
-
:willneed,
|
10
|
-
:dontneed,
|
11
|
-
:noreuse
|
12
|
-
return nil
|
13
|
-
when Symbol
|
14
|
-
raise NotImplementedError, "Unsupported advice #{advice}"
|
15
|
-
else
|
16
|
-
raise TypeError, "advice must be a Symbol"
|
17
|
-
end
|
18
|
-
end unless method_defined? :advise
|
19
|
-
end
|
20
|
-
|
21
|
-
class << IO
|
22
|
-
# Standard in Ruby 1.9.3 See official documentation[http://ruby-doc.org/core-1.9.3/IO.html#method-c-write]
|
23
|
-
def write(name, string, offset = nil, options = Backports::Undefined)
|
24
|
-
Backports.write(false, name, string, offset, options)
|
25
|
-
end unless method_defined? :write
|
1
|
+
require 'backports/tools'
|
26
2
|
|
27
|
-
|
28
|
-
# This method does support an options hash, see http://bugs.ruby-lang.org/issues/5782
|
29
|
-
def binwrite(name, string, offset = nil, options = Backports::Undefined)
|
30
|
-
Backports.write(true, name, string, offset, options)
|
31
|
-
end unless method_defined? :binwrite
|
32
|
-
end
|
3
|
+
Backports.require_relative_dir
|
@@ -0,0 +1,24 @@
|
|
1
|
+
unless IO.method_defined? :advise
|
2
|
+
require 'backports/tools'
|
3
|
+
|
4
|
+
class IO
|
5
|
+
def advise(advice, offset=0, len=0)
|
6
|
+
raise RangeError if Backports.coerce_to_int(offset) >= 1<<31
|
7
|
+
raise RangeError if Backports.coerce_to_int(len) >= 1<<31
|
8
|
+
raise IOError if closed?
|
9
|
+
case advice
|
10
|
+
when :normal,
|
11
|
+
:sequential,
|
12
|
+
:random,
|
13
|
+
:willneed,
|
14
|
+
:dontneed,
|
15
|
+
:noreuse
|
16
|
+
return nil
|
17
|
+
when Symbol
|
18
|
+
raise NotImplementedError, "Unsupported advice #{advice}"
|
19
|
+
else
|
20
|
+
raise TypeError, "advice must be a Symbol"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,39 +1,3 @@
|
|
1
|
-
|
2
|
-
# Standard in Ruby 1.9.3 See official documentation[http://ruby-doc.org/core-1.9.3/String.html#byteslice]
|
3
|
-
def byteslice(start, len = Backports::Undefined)
|
4
|
-
# Argument parsing & checking
|
5
|
-
if Backports::Undefined == len
|
6
|
-
if start.is_a?(Range)
|
7
|
-
range = start
|
8
|
-
start = Backports.coerce_to_int(range.begin)
|
9
|
-
start += bytesize if start < 0
|
10
|
-
last = Backports.coerce_to_int(range.end)
|
11
|
-
last += bytesize if last < 0
|
12
|
-
last += 1 unless range.exclude_end?
|
13
|
-
len = last - start
|
14
|
-
else
|
15
|
-
start = Backports.coerce_to_int(start)
|
16
|
-
start += bytesize if start < 0
|
17
|
-
len = 1
|
18
|
-
return if start >= bytesize
|
19
|
-
end
|
20
|
-
else
|
21
|
-
start = Backports.coerce_to_int(start)
|
22
|
-
start += bytesize if start < 0
|
23
|
-
len = Backports.coerce_to_int(len)
|
24
|
-
return if len < 0
|
25
|
-
end
|
26
|
-
return if start < 0 || start > bytesize
|
27
|
-
len = 0 if len < 0
|
28
|
-
# Actual implementation:
|
29
|
-
str = unpack("@#{start}a#{len}").first
|
30
|
-
str = dup.replace(str) unless self.instance_of?(String) # Must return subclass
|
31
|
-
str.force_encoding(encoding)
|
32
|
-
end unless method_defined? :byteslice
|
1
|
+
require 'backports/tools'
|
33
2
|
|
34
|
-
|
35
|
-
def prepend(other_str)
|
36
|
-
replace Backports.coerce_to_str(other_str) + self
|
37
|
-
self
|
38
|
-
end unless method_defined? :prepend
|
39
|
-
end
|
3
|
+
Backports.require_relative_dir
|
@@ -0,0 +1,36 @@
|
|
1
|
+
unless String.method_defined? :byteslice
|
2
|
+
require 'backports/tools'
|
3
|
+
|
4
|
+
class String
|
5
|
+
def byteslice(start, len = Backports::Undefined)
|
6
|
+
# Argument parsing & checking
|
7
|
+
if Backports::Undefined == len
|
8
|
+
if start.is_a?(Range)
|
9
|
+
range = start
|
10
|
+
start = Backports.coerce_to_int(range.begin)
|
11
|
+
start += bytesize if start < 0
|
12
|
+
last = Backports.coerce_to_int(range.end)
|
13
|
+
last += bytesize if last < 0
|
14
|
+
last += 1 unless range.exclude_end?
|
15
|
+
len = last - start
|
16
|
+
else
|
17
|
+
start = Backports.coerce_to_int(start)
|
18
|
+
start += bytesize if start < 0
|
19
|
+
len = 1
|
20
|
+
return if start >= bytesize
|
21
|
+
end
|
22
|
+
else
|
23
|
+
start = Backports.coerce_to_int(start)
|
24
|
+
start += bytesize if start < 0
|
25
|
+
len = Backports.coerce_to_int(len)
|
26
|
+
return if len < 0
|
27
|
+
end
|
28
|
+
return if start < 0 || start > bytesize
|
29
|
+
len = 0 if len < 0
|
30
|
+
# Actual implementation:
|
31
|
+
str = unpack("@#{start}a#{len}").first
|
32
|
+
str = dup.replace(str) unless self.instance_of?(String) # Must return subclass
|
33
|
+
str.force_encoding(encoding)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/backports/1.9.rb
CHANGED
data/lib/backports/2.0.0.rb
CHANGED
@@ -1,30 +1,3 @@
|
|
1
|
-
|
2
|
-
def bsearch
|
3
|
-
return to_enum(__method__) unless block_given?
|
4
|
-
from = 0
|
5
|
-
to = size - 1
|
6
|
-
satisfied = nil
|
7
|
-
while from <= to do
|
8
|
-
midpoint = (from + to).div(2)
|
9
|
-
result = yield(cur = self[midpoint])
|
10
|
-
case result
|
11
|
-
when Numeric
|
12
|
-
return cur if result == 0
|
13
|
-
result = result < 0
|
14
|
-
when true
|
15
|
-
satisfied = cur
|
16
|
-
when nil, false
|
17
|
-
# nothing to do
|
18
|
-
else
|
19
|
-
raise TypeError, "wrong argument type #{result.class} (must be numeric, true, false or nil)"
|
20
|
-
end
|
1
|
+
require 'backports/tools'
|
21
2
|
|
22
|
-
|
23
|
-
to = midpoint - 1
|
24
|
-
else
|
25
|
-
from = midpoint + 1
|
26
|
-
end
|
27
|
-
end
|
28
|
-
satisfied
|
29
|
-
end unless method_defined? :bsearch
|
30
|
-
end
|
3
|
+
Backports.require_relative_dir
|
@@ -0,0 +1,32 @@
|
|
1
|
+
unless Array.method_defined? :bsearch
|
2
|
+
class Array
|
3
|
+
def bsearch
|
4
|
+
return to_enum(__method__) unless block_given?
|
5
|
+
from = 0
|
6
|
+
to = size - 1
|
7
|
+
satisfied = nil
|
8
|
+
while from <= to do
|
9
|
+
midpoint = (from + to).div(2)
|
10
|
+
result = yield(cur = self[midpoint])
|
11
|
+
case result
|
12
|
+
when Numeric
|
13
|
+
return cur if result == 0
|
14
|
+
result = result < 0
|
15
|
+
when true
|
16
|
+
satisfied = cur
|
17
|
+
when nil, false
|
18
|
+
# nothing to do
|
19
|
+
else
|
20
|
+
raise TypeError, "wrong argument type #{result.class} (must be numeric, true, false or nil)"
|
21
|
+
end
|
22
|
+
|
23
|
+
if result
|
24
|
+
to = midpoint - 1
|
25
|
+
else
|
26
|
+
from = midpoint + 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
satisfied
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,12 +1,3 @@
|
|
1
|
-
|
2
|
-
module Enumerable
|
3
|
-
def lazy
|
4
|
-
klass = Enumerator::Lazy.send :class_variable_get, :@@lazy_with_no_block # Note: class_variable_get is private in 1.8
|
5
|
-
Enumerator::Lazy.new(klass.new(self, :each, []))
|
6
|
-
end
|
7
|
-
end
|
1
|
+
require 'backports/tools'
|
8
2
|
|
9
|
-
|
10
|
-
require_relative 'enumerator/lazy'
|
11
|
-
end
|
12
|
-
end
|
3
|
+
Backports.require_relative_dir
|
@@ -0,0 +1,216 @@
|
|
1
|
+
unless Enumerable.method_defined? :lazy
|
2
|
+
require 'backports/tools'
|
3
|
+
require 'backports/1.9.1/enumerator/new'
|
4
|
+
|
5
|
+
module Enumerable
|
6
|
+
def lazy
|
7
|
+
klass = Enumerator::Lazy.send :class_variable_get, :@@lazy_with_no_block # Note: class_variable_get is private in 1.8
|
8
|
+
Enumerator::Lazy.new(klass.new(self, :each, []))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Enumerator
|
13
|
+
class Yielder
|
14
|
+
# Current API for Lazy Enumerator does not provide an easy way
|
15
|
+
# to handle internal state. We "cheat" and use yielder to hold it for us.
|
16
|
+
# A new yielder is created when generating or after a `rewind`.
|
17
|
+
# This way we avoid issues like http://bugs.ruby-lang.org/issues/7691
|
18
|
+
# or http://bugs.ruby-lang.org/issues/7696
|
19
|
+
attr_accessor :backports_memo
|
20
|
+
end
|
21
|
+
|
22
|
+
class Lazy < Enumerator
|
23
|
+
@@done = :__backports_lazy_enumeration_done__ # used internally to bail out of an iteration
|
24
|
+
@@lazy_with_no_block = Struct.new(:object, :method, :args) # used internally to create lazy without block
|
25
|
+
|
26
|
+
def initialize(obj)
|
27
|
+
if obj.is_a?(@@lazy_with_no_block)
|
28
|
+
@inspect_info = obj
|
29
|
+
return super(@receiver = obj.object, @method = obj.method || :each, * @args = obj.args)
|
30
|
+
end
|
31
|
+
raise ArgumentError, "must supply a block" unless block_given?
|
32
|
+
@receiver = obj
|
33
|
+
super() do |yielder, *args|
|
34
|
+
catch @@done do
|
35
|
+
obj.each(*args) do |*x|
|
36
|
+
yield yielder, *x
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
alias_method :force, :to_a
|
43
|
+
|
44
|
+
def lazy
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_enum(method = :each, *args)
|
49
|
+
Lazy.new(@@lazy_with_no_block.new(self, method, args))
|
50
|
+
end
|
51
|
+
alias_method :enum_for, :to_enum
|
52
|
+
|
53
|
+
def inspect
|
54
|
+
suff = ''
|
55
|
+
suff << ":#{@method}" unless @method.nil? || @method == :each
|
56
|
+
suff << "(#{@args.inspect[1...-1]})" if @args && !@args.empty?
|
57
|
+
"#<#{self.class}: #{@receiver.inspect}#{suff}>"
|
58
|
+
end
|
59
|
+
|
60
|
+
{
|
61
|
+
:slice_before => //,
|
62
|
+
:with_index => [],
|
63
|
+
:cycle => [],
|
64
|
+
:each_with_object => 42,
|
65
|
+
:each_slice => 42,
|
66
|
+
:each_entry => [],
|
67
|
+
:each_cons => 42,
|
68
|
+
}.each do |method, args|
|
69
|
+
next unless Enumerator.method_defined? method
|
70
|
+
unless [].lazy.send(method, *args).is_a?(Lazy) # Nothing to do if already backported, since it would use to_enum...
|
71
|
+
module_eval <<-EOT, __FILE__, __LINE__ + 1
|
72
|
+
def #{method}(*args) # def cycle(*args)
|
73
|
+
return to_enum(:#{method}, *args) unless block_given? # return to_enum(:cycle, *args) unless block_given?
|
74
|
+
super # super
|
75
|
+
end # end
|
76
|
+
EOT
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def chunk(*)
|
81
|
+
super.lazy
|
82
|
+
end if Enumerable.method_defined?(:chunk) && ![].lazy.chunk{}.is_a?(Lazy)
|
83
|
+
|
84
|
+
def map
|
85
|
+
raise ArgumentError, "tried to call lazy map without a block" unless block_given?
|
86
|
+
Lazy.new(self) do |yielder, *values|
|
87
|
+
yielder << yield(*values)
|
88
|
+
end.__set_inspect :map
|
89
|
+
end
|
90
|
+
alias_method :collect, :map
|
91
|
+
|
92
|
+
def select
|
93
|
+
raise ArgumentError, "tried to call lazy select without a block" unless block_given?
|
94
|
+
Lazy.new(self) do |yielder, *values|
|
95
|
+
values = values.first unless values.size > 1
|
96
|
+
yielder.yield values if yield values
|
97
|
+
end.__set_inspect :select
|
98
|
+
end
|
99
|
+
alias_method :find_all, :select
|
100
|
+
|
101
|
+
def reject
|
102
|
+
raise ArgumentError, "tried to call lazy reject without a block" unless block_given?
|
103
|
+
Lazy.new(self) do |yielder, *values|
|
104
|
+
values = values.first unless values.size > 1
|
105
|
+
yielder.yield(values) unless yield values
|
106
|
+
end.__set_inspect :reject
|
107
|
+
end
|
108
|
+
|
109
|
+
def grep(pattern)
|
110
|
+
if block_given?
|
111
|
+
# Split for performance
|
112
|
+
Lazy.new(self) do |yielder, *values|
|
113
|
+
values = values.first unless values.size > 1
|
114
|
+
yielder.yield(yield(values)) if pattern === values
|
115
|
+
end
|
116
|
+
else
|
117
|
+
Lazy.new(self) do |yielder, *values|
|
118
|
+
values = values.first unless values.size > 1
|
119
|
+
yielder.yield(values) if pattern === values
|
120
|
+
end
|
121
|
+
end.__set_inspect :grep, [pattern]
|
122
|
+
end
|
123
|
+
|
124
|
+
def drop(n)
|
125
|
+
n = Backports::coerce_to_int(n)
|
126
|
+
Lazy.new(self) do |yielder, *values|
|
127
|
+
data = yielder.backports_memo ||= {:remain => n}
|
128
|
+
if data[:remain] > 0
|
129
|
+
data[:remain] -= 1
|
130
|
+
else
|
131
|
+
yielder.yield(*values)
|
132
|
+
end
|
133
|
+
end.__set_inspect :drop, [n]
|
134
|
+
end
|
135
|
+
|
136
|
+
def drop_while
|
137
|
+
raise ArgumentError, "tried to call lazy drop_while without a block" unless block_given?
|
138
|
+
Lazy.new(self) do |yielder, *values|
|
139
|
+
data = yielder.backports_memo ||= {:dropping => true}
|
140
|
+
yielder.yield(*values) unless data[:dropping] &&= yield(*values)
|
141
|
+
end.__set_inspect :drop_while
|
142
|
+
end
|
143
|
+
|
144
|
+
def take(n)
|
145
|
+
n = Backports::coerce_to_int(n)
|
146
|
+
raise ArgumentError, 'attempt to take negative size' if n < 0
|
147
|
+
Lazy.new(n == 0 ? [] : self) do |yielder, *values|
|
148
|
+
data = yielder.backports_memo ||= {:remain => n}
|
149
|
+
yielder.yield(*values)
|
150
|
+
throw @@done if (data[:remain] -= 1) == 0
|
151
|
+
end.__set_inspect :take, [n], self
|
152
|
+
end
|
153
|
+
|
154
|
+
def take_while
|
155
|
+
raise ArgumentError, "tried to call lazy take_while without a block" unless block_given?
|
156
|
+
Lazy.new(self) do |yielder, *values|
|
157
|
+
throw @@done unless yield(*values)
|
158
|
+
yielder.yield(*values)
|
159
|
+
end.__set_inspect :take_while
|
160
|
+
end
|
161
|
+
|
162
|
+
def flat_map
|
163
|
+
raise ArgumentError, "tried to call lazy flat_map without a block" unless block_given?
|
164
|
+
Lazy.new(self) do |yielder, *values|
|
165
|
+
result = yield(*values)
|
166
|
+
ary = Backports.is_array?(result)
|
167
|
+
if ary || (result.respond_to?(:each) && result.respond_to?(:force))
|
168
|
+
(ary || result).each{|x| yielder << x }
|
169
|
+
else
|
170
|
+
yielder << result
|
171
|
+
end
|
172
|
+
end.__set_inspect :flat_map
|
173
|
+
end
|
174
|
+
alias_method :collect_concat, :flat_map
|
175
|
+
|
176
|
+
def zip(*args)
|
177
|
+
return super if block_given?
|
178
|
+
arys = args.map{ |arg| Backports.is_array?(arg) }
|
179
|
+
if arys.all?
|
180
|
+
# Handle trivial case of multiple array arguments separately
|
181
|
+
# by avoiding Enumerator#next for efficiency & compatibility
|
182
|
+
Lazy.new(self) do |yielder, *values|
|
183
|
+
data = yielder.backports_memo ||= {:iter => 0}
|
184
|
+
values = values.first unless values.size > 1
|
185
|
+
yielder << arys.map{|ary| ary[data[:iter]]}.unshift(values)
|
186
|
+
data[:iter] += 1
|
187
|
+
end
|
188
|
+
else
|
189
|
+
args.each do |a|
|
190
|
+
raise TypeError, "wrong argument type #{a.class} (must respond to :each)" unless a.respond_to? :each
|
191
|
+
end
|
192
|
+
Lazy.new(self) do |yielder, *values|
|
193
|
+
enums = yielder.backports_memo ||= args.map(&:to_enum)
|
194
|
+
values = values.first unless values.size > 1
|
195
|
+
others = enums.map do |arg|
|
196
|
+
begin
|
197
|
+
arg.next
|
198
|
+
rescue StopIteration
|
199
|
+
nil
|
200
|
+
end
|
201
|
+
end
|
202
|
+
yielder << others.unshift(values)
|
203
|
+
end
|
204
|
+
end.__set_inspect :zip, args
|
205
|
+
end
|
206
|
+
|
207
|
+
protected
|
208
|
+
def __set_inspect(method, args = nil, receiver = nil)
|
209
|
+
@method = method
|
210
|
+
@args = args
|
211
|
+
@receiver = receiver if receiver
|
212
|
+
self
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|