backports 3.0.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (487) hide show
  1. data/.gitignore +1 -1
  2. data/.gitmodules +3 -0
  3. data/.travis.yml +11 -2
  4. data/CHANGELOG.rdoc +6 -0
  5. data/Gemfile +20 -0
  6. data/Gemfile.lock +24 -0
  7. data/README.rdoc +39 -11
  8. data/Rakefile +98 -1
  9. data/default.mspec +9 -0
  10. data/lib/backports.rb +4 -4
  11. data/lib/backports/1.8.7.rb +2 -3
  12. data/lib/backports/1.8.7/argf.rb +2 -43
  13. data/lib/backports/1.8.7/argf/bytes.rb +1 -0
  14. data/lib/backports/1.8.7/argf/chars.rb +1 -0
  15. data/lib/backports/1.8.7/argf/each.rb +3 -0
  16. data/lib/backports/1.8.7/argf/each_byte.rb +9 -0
  17. data/lib/backports/1.8.7/argf/each_char.rb +35 -0
  18. data/lib/backports/1.8.7/argf/each_line.rb +3 -0
  19. data/lib/backports/1.8.7/argf/getbyte.rb +5 -0
  20. data/lib/backports/1.8.7/argf/lines.rb +5 -0
  21. data/lib/backports/1.8.7/argf/readbyte.rb +5 -0
  22. data/lib/backports/1.8.7/array.rb +2 -207
  23. data/lib/backports/1.8.7/array/collect.rb +3 -0
  24. data/lib/backports/1.8.7/array/combination.rb +24 -0
  25. data/lib/backports/1.8.7/array/cycle.rb +16 -0
  26. data/lib/backports/1.8.7/array/delete_if.rb +3 -0
  27. data/lib/backports/1.8.7/array/each.rb +3 -0
  28. data/lib/backports/1.8.7/array/each_index.rb +3 -0
  29. data/lib/backports/1.8.7/array/find_index.rb +1 -0
  30. data/lib/backports/1.8.7/array/flatten.rb +47 -0
  31. data/lib/backports/1.8.7/array/index.rb +15 -0
  32. data/lib/backports/1.8.7/array/map.rb +3 -0
  33. data/lib/backports/1.8.7/array/permutation.rb +30 -0
  34. data/lib/backports/1.8.7/array/pop.rb +15 -0
  35. data/lib/backports/1.8.7/array/product.rb +32 -0
  36. data/lib/backports/1.8.7/array/reject.rb +3 -0
  37. data/lib/backports/1.8.7/array/reverse_each.rb +3 -0
  38. data/lib/backports/1.8.7/array/rindex.rb +15 -0
  39. data/lib/backports/1.8.7/array/select.rb +3 -0
  40. data/lib/backports/1.8.7/array/shift.rb +13 -0
  41. data/lib/backports/1.8.7/array/shuffle.rb +17 -0
  42. data/lib/backports/1.8.7/binding.rb +3 -6
  43. data/lib/backports/1.8.7/binding/eval.rb +7 -0
  44. data/lib/backports/1.8.7/dir.rb +2 -57
  45. data/lib/backports/1.8.7/dir/each.rb +7 -0
  46. data/lib/backports/1.8.7/dir/foreach.rb +9 -0
  47. data/lib/backports/1.8.7/dir/mktmpdir.rb +44 -0
  48. data/lib/backports/1.8.7/enumerable.rb +2 -240
  49. data/lib/backports/1.8.7/enumerable/count.rb +17 -0
  50. data/lib/backports/1.8.7/enumerable/cycle.rb +24 -0
  51. data/lib/backports/1.8.7/enumerable/detect.rb +3 -0
  52. data/lib/backports/1.8.7/enumerable/drop.rb +13 -0
  53. data/lib/backports/1.8.7/enumerable/drop_while.rb +16 -0
  54. data/lib/backports/1.8.7/enumerable/each_cons.rb +4 -0
  55. data/lib/backports/1.8.7/enumerable/each_slice.rb +4 -0
  56. data/lib/backports/1.8.7/enumerable/each_with_index.rb +3 -0
  57. data/lib/backports/1.8.7/enumerable/entries.rb +11 -0
  58. data/lib/backports/1.8.7/enumerable/find.rb +3 -0
  59. data/lib/backports/1.8.7/enumerable/find_all.rb +3 -0
  60. data/lib/backports/1.8.7/enumerable/find_index.rb +21 -0
  61. data/lib/backports/1.8.7/enumerable/first.rb +21 -0
  62. data/lib/backports/1.8.7/enumerable/group_by.rb +14 -0
  63. data/lib/backports/1.8.7/enumerable/inject.rb +14 -0
  64. data/lib/backports/1.8.7/enumerable/max_by.rb +16 -0
  65. data/lib/backports/1.8.7/enumerable/min_by.rb +16 -0
  66. data/lib/backports/1.8.7/enumerable/minmax.rb +21 -0
  67. data/lib/backports/1.8.7/enumerable/minmax_by.rb +19 -0
  68. data/lib/backports/1.8.7/enumerable/none.rb +7 -0
  69. data/lib/backports/1.8.7/enumerable/one.rb +23 -0
  70. data/lib/backports/1.8.7/enumerable/partition.rb +3 -0
  71. data/lib/backports/1.8.7/enumerable/reduce.rb +1 -0
  72. data/lib/backports/1.8.7/enumerable/reject.rb +3 -0
  73. data/lib/backports/1.8.7/enumerable/reverse_each.rb +12 -0
  74. data/lib/backports/1.8.7/enumerable/select.rb +3 -0
  75. data/lib/backports/1.8.7/enumerable/sort_by.rb +3 -0
  76. data/lib/backports/1.8.7/enumerable/take.rb +9 -0
  77. data/lib/backports/1.8.7/enumerable/take_while.rb +14 -0
  78. data/lib/backports/1.8.7/enumerable/to_a.rb +12 -0
  79. data/lib/backports/1.8.7/enumerator.rb +2 -31
  80. data/lib/backports/1.8.7/enumerator/each.rb +6 -0
  81. data/lib/backports/1.8.7/enumerator/next.rb +15 -0
  82. data/lib/backports/1.8.7/enumerator/rewind.rb +13 -0
  83. data/lib/backports/1.8.7/enumerator/with_index.rb +14 -0
  84. data/lib/backports/1.8.7/env.rb +3 -3
  85. data/lib/backports/1.8.7/env/delete_if.rb +3 -0
  86. data/lib/backports/1.8.7/env/each.rb +3 -0
  87. data/lib/backports/1.8.7/env/each_key.rb +3 -0
  88. data/lib/backports/1.8.7/env/each_pair.rb +3 -0
  89. data/lib/backports/1.8.7/env/each_value.rb +3 -0
  90. data/lib/backports/1.8.7/env/reject.rb +4 -0
  91. data/lib/backports/1.8.7/env/select.rb +3 -0
  92. data/lib/backports/1.8.7/fixnum.rb +2 -10
  93. data/lib/backports/1.8.7/fixnum/div.rb +7 -0
  94. data/lib/backports/1.8.7/fixnum/fdiv.rb +7 -0
  95. data/lib/backports/1.8.7/float.rb +3 -4
  96. data/lib/backports/1.8.7/float/fdiv.rb +3 -0
  97. data/lib/backports/1.8.7/gc.rb +2 -10
  98. data/lib/backports/1.8.7/gc/stress.rb +9 -0
  99. data/lib/backports/1.8.7/hash.rb +2 -41
  100. data/lib/backports/1.8.7/hash/constructor.rb +25 -0
  101. data/lib/backports/1.8.7/hash/delete_if.rb +3 -0
  102. data/lib/backports/1.8.7/hash/each.rb +3 -0
  103. data/lib/backports/1.8.7/hash/each_key.rb +3 -0
  104. data/lib/backports/1.8.7/hash/each_pair.rb +3 -0
  105. data/lib/backports/1.8.7/hash/each_value.rb +3 -0
  106. data/lib/backports/1.8.7/hash/eql.rb +1 -0
  107. data/lib/backports/1.8.7/hash/hash.rb +17 -0
  108. data/lib/backports/1.8.7/hash/key.rb +3 -0
  109. data/lib/backports/1.8.7/hash/reject.rb +3 -0
  110. data/lib/backports/1.8.7/hash/select.rb +3 -0
  111. data/lib/backports/1.8.7/integer.rb +2 -23
  112. data/lib/backports/1.8.7/integer/downto.rb +3 -0
  113. data/lib/backports/1.8.7/integer/even.rb +7 -0
  114. data/lib/backports/1.8.7/integer/odd.rb +7 -0
  115. data/lib/backports/1.8.7/integer/ord.rb +7 -0
  116. data/lib/backports/1.8.7/integer/pred.rb +7 -0
  117. data/lib/backports/1.8.7/integer/times.rb +3 -0
  118. data/lib/backports/1.8.7/integer/upto.rb +3 -0
  119. data/lib/backports/1.8.7/io.rb +2 -42
  120. data/lib/backports/1.8.7/io/bytes.rb +1 -0
  121. data/lib/backports/1.8.7/io/chars.rb +1 -0
  122. data/lib/backports/1.8.7/io/each.rb +3 -0
  123. data/lib/backports/1.8.7/io/each_byte.rb +6 -0
  124. data/lib/backports/1.8.7/io/each_char.rb +34 -0
  125. data/lib/backports/1.8.7/io/each_line.rb +6 -0
  126. data/lib/backports/1.8.7/io/foreach.rb +7 -0
  127. data/lib/backports/1.8.7/io/getbyte.rb +3 -0
  128. data/lib/backports/1.8.7/io/lines.rb +1 -0
  129. data/lib/backports/1.8.7/io/readbyte.rb +3 -0
  130. data/lib/backports/1.8.7/kernel.rb +2 -35
  131. data/lib/backports/1.8.7/kernel/__method__.rb +8 -0
  132. data/lib/backports/1.8.7/kernel/instance_exec.rb +10 -0
  133. data/lib/backports/1.8.7/kernel/tap.rb +8 -0
  134. data/lib/backports/1.8.7/method.rb +2 -46
  135. data/lib/backports/1.8.7/method/name.rb +49 -0
  136. data/lib/backports/1.8.7/module.rb +3 -7
  137. data/lib/backports/1.8.7/module/class_exec.rb +1 -0
  138. data/lib/backports/1.8.7/module/module_exec.rb +11 -0
  139. data/lib/backports/1.8.7/numeric.rb +3 -3
  140. data/lib/backports/1.8.7/numeric/step.rb +3 -0
  141. data/lib/backports/1.8.7/object_space.rb +3 -5
  142. data/lib/backports/1.8.7/object_space/each_object.rb +5 -0
  143. data/lib/backports/1.8.7/proc.rb +3 -4
  144. data/lib/backports/1.8.7/proc/yield.rb +3 -0
  145. data/lib/backports/1.8.7/process.rb +3 -5
  146. data/lib/backports/1.8.7/process/exec.rb +3 -0
  147. data/lib/backports/1.8.7/range.rb +3 -4
  148. data/lib/backports/1.8.7/range/each.rb +3 -0
  149. data/lib/backports/1.8.7/range/step.rb +3 -0
  150. data/lib/backports/1.8.7/regexp.rb +3 -12
  151. data/lib/backports/1.8.7/regexp/union.rb +11 -0
  152. data/lib/backports/1.8.7/stop_iteration.rb +14 -0
  153. data/lib/backports/1.8.7/string.rb +2 -91
  154. data/lib/backports/1.8.7/string/bytes.rb +1 -0
  155. data/lib/backports/1.8.7/string/bytesize.rb +3 -0
  156. data/lib/backports/1.8.7/string/each.rb +3 -0
  157. data/lib/backports/1.8.7/string/each_byte.rb +5 -0
  158. data/lib/backports/1.8.7/string/each_char.rb +13 -0
  159. data/lib/backports/1.8.7/string/each_line.rb +5 -0
  160. data/lib/backports/1.8.7/string/end_with.rb +12 -0
  161. data/lib/backports/1.8.7/string/lines.rb +1 -0
  162. data/lib/backports/1.8.7/string/partition.rb +20 -0
  163. data/lib/backports/1.8.7/string/rpartition.rb +19 -0
  164. data/lib/backports/1.8.7/string/start_with.rb +12 -0
  165. data/lib/backports/1.8.7/string/upto.rb +15 -0
  166. data/lib/backports/1.8.7/struct.rb +3 -3
  167. data/lib/backports/1.8.7/struct/each.rb +3 -0
  168. data/lib/backports/1.8.7/struct/each_pair.rb +3 -0
  169. data/lib/backports/1.8.7/symbol.rb +3 -6
  170. data/lib/backports/1.8.7/symbol/to_proc.rb +8 -0
  171. data/lib/backports/1.8.8.rb +1 -3
  172. data/lib/backports/1.8.rb +1 -3
  173. data/lib/backports/1.9.1.rb +2 -4
  174. data/lib/backports/1.9.1/array.rb +3 -8
  175. data/lib/backports/1.9.1/array/sample.rb +19 -0
  176. data/lib/backports/1.9.1/array/try_convert.rb +7 -0
  177. data/lib/backports/1.9.1/dir.rb +3 -3
  178. data/lib/backports/1.9.1/dir/to_path.rb +3 -0
  179. data/lib/backports/1.9.1/enumerable.rb +2 -18
  180. data/lib/backports/1.9.1/enumerable/each_with_index.rb +14 -0
  181. data/lib/backports/1.9.1/enumerable/each_with_object.rb +9 -0
  182. data/lib/backports/1.9.1/enumerator.rb +2 -40
  183. data/lib/backports/1.9.1/enumerator/new.rb +40 -0
  184. data/lib/backports/1.9.1/enumerator/with_object.rb +6 -0
  185. data/lib/backports/1.9.1/env.rb +3 -3
  186. data/lib/backports/1.9.1/env/key.rb +5 -0
  187. data/lib/backports/1.9.1/file.rb +2 -43
  188. data/lib/backports/1.9.1/file/atime.rb +5 -0
  189. data/lib/backports/1.9.1/file/basename.rb +5 -0
  190. data/lib/backports/1.9.1/file/binary.rb +6 -0
  191. data/lib/backports/1.9.1/file/blockdev.rb +5 -0
  192. data/lib/backports/1.9.1/file/chardev.rb +5 -0
  193. data/lib/backports/1.9.1/file/chmod.rb +5 -0
  194. data/lib/backports/1.9.1/file/chown.rb +5 -0
  195. data/lib/backports/1.9.1/file/ctime.rb +5 -0
  196. data/lib/backports/1.9.1/file/delete.rb +5 -0
  197. data/lib/backports/1.9.1/file/directory.rb +5 -0
  198. data/lib/backports/1.9.1/file/dirname.rb +5 -0
  199. data/lib/backports/1.9.1/file/executable.rb +5 -0
  200. data/lib/backports/1.9.1/file/executable_real.rb +5 -0
  201. data/lib/backports/1.9.1/file/exist.rb +5 -0
  202. data/lib/backports/1.9.1/file/exists.rb +5 -0
  203. data/lib/backports/1.9.1/file/expand_path.rb +14 -0
  204. data/lib/backports/1.9.1/file/extname.rb +5 -0
  205. data/lib/backports/1.9.1/file/file.rb +5 -0
  206. data/lib/backports/1.9.1/file/ftype.rb +5 -0
  207. data/lib/backports/1.9.1/file/grpowned.rb +5 -0
  208. data/lib/backports/1.9.1/file/join.rb +5 -0
  209. data/lib/backports/1.9.1/file/lchmod.rb +5 -0
  210. data/lib/backports/1.9.1/file/lchown.rb +5 -0
  211. data/lib/backports/1.9.1/file/link.rb +5 -0
  212. data/lib/backports/1.9.1/file/lstat.rb +5 -0
  213. data/lib/backports/1.9.1/file/mtime.rb +5 -0
  214. data/lib/backports/1.9.1/file/new.rb +5 -0
  215. data/lib/backports/1.9.1/file/open.rb +23 -0
  216. data/lib/backports/1.9.1/file/owned.rb +5 -0
  217. data/lib/backports/1.9.1/file/pipe.rb +5 -0
  218. data/lib/backports/1.9.1/file/readable.rb +5 -0
  219. data/lib/backports/1.9.1/file/readable_real.rb +5 -0
  220. data/lib/backports/1.9.1/file/readlink.rb +5 -0
  221. data/lib/backports/1.9.1/file/rename.rb +5 -0
  222. data/lib/backports/1.9.1/file/setgid.rb +5 -0
  223. data/lib/backports/1.9.1/file/setuid.rb +5 -0
  224. data/lib/backports/1.9.1/file/size.rb +14 -0
  225. data/lib/backports/1.9.1/file/socket.rb +5 -0
  226. data/lib/backports/1.9.1/file/split.rb +5 -0
  227. data/lib/backports/1.9.1/file/stat.rb +5 -0
  228. data/lib/backports/1.9.1/file/sticky.rb +5 -0
  229. data/lib/backports/1.9.1/file/symlink.rb +6 -0
  230. data/lib/backports/1.9.1/file/to_path.rb +3 -0
  231. data/lib/backports/1.9.1/file/truncate.rb +5 -0
  232. data/lib/backports/1.9.1/file/unlink.rb +5 -0
  233. data/lib/backports/1.9.1/file/writable.rb +5 -0
  234. data/lib/backports/1.9.1/file/writable_real.rb +5 -0
  235. data/lib/backports/1.9.1/file/zero.rb +5 -0
  236. data/lib/backports/1.9.1/float.rb +3 -19
  237. data/lib/backports/1.9.1/float/round.rb +21 -0
  238. data/lib/backports/1.9.1/hash.rb +2 -35
  239. data/lib/backports/1.9.1/hash/assoc.rb +12 -0
  240. data/lib/backports/1.9.1/hash/default_proc.rb +14 -0
  241. data/lib/backports/1.9.1/hash/rassoc.rb +9 -0
  242. data/lib/backports/1.9.1/hash/try_convert.rb +7 -0
  243. data/lib/backports/1.9.1/integer.rb +2 -21
  244. data/lib/backports/1.9.1/integer/magnitude.rb +3 -0
  245. data/lib/backports/1.9.1/integer/round.rb +24 -0
  246. data/lib/backports/1.9.1/io.rb +2 -33
  247. data/lib/backports/1.9.1/io/binread.rb +10 -0
  248. data/lib/backports/1.9.1/io/open.rb +21 -0
  249. data/lib/backports/1.9.1/io/try_convert.rb +7 -0
  250. data/lib/backports/1.9.1/io/ungetbyte.rb +3 -0
  251. data/lib/backports/1.9.1/kernel.rb +2 -39
  252. data/lib/backports/1.9.1/kernel/__callee__.rb +7 -0
  253. data/lib/backports/1.9.1/kernel/define_singleton_method.rb +9 -0
  254. data/lib/backports/1.9.1/kernel/public_method.rb +11 -0
  255. data/lib/backports/1.9.1/kernel/public_send.rb +13 -0
  256. data/lib/backports/1.9.1/kernel/require_relative.rb +14 -0
  257. data/lib/backports/1.9.1/math.rb +2 -24
  258. data/lib/backports/1.9.1/math/log.rb +22 -0
  259. data/lib/backports/1.9.1/math/log2.rb +5 -0
  260. data/lib/backports/1.9.1/numeric.rb +3 -9
  261. data/lib/backports/1.9.1/numeric/round.rb +11 -0
  262. data/lib/backports/1.9.1/proc.rb +2 -53
  263. data/lib/backports/1.9.1/proc/case_compare.rb +6 -0
  264. data/lib/backports/1.9.1/proc/curry.rb +24 -0
  265. data/lib/backports/1.9.1/proc/lambda.rb +40 -0
  266. data/lib/backports/1.9.1/range.rb +3 -3
  267. data/lib/backports/1.9.1/range/cover.rb +3 -0
  268. data/lib/backports/1.9.1/regexp.rb +3 -8
  269. data/lib/backports/1.9.1/regexp/try_convert.rb +7 -0
  270. data/lib/backports/1.9.1/stdlib.rb +1 -1
  271. data/lib/backports/1.9.1/string.rb +2 -44
  272. data/lib/backports/1.9.1/string/ascii_only.rb +7 -0
  273. data/lib/backports/1.9.1/string/chr.rb +7 -0
  274. data/lib/backports/1.9.1/string/clear.rb +8 -0
  275. data/lib/backports/1.9.1/string/codepoints.rb +8 -0
  276. data/lib/backports/1.9.1/string/each_codepoint.rb +3 -0
  277. data/lib/backports/1.9.1/string/getbyte.rb +3 -0
  278. data/lib/backports/1.9.1/string/ord.rb +7 -0
  279. data/lib/backports/1.9.1/string/setbyte.rb +3 -0
  280. data/lib/backports/1.9.1/string/try_convert.rb +7 -0
  281. data/lib/backports/1.9.1/symbol.rb +2 -31
  282. data/lib/backports/1.9.1/symbol/capitalize.rb +7 -0
  283. data/lib/backports/1.9.1/symbol/casecmp.rb +8 -0
  284. data/lib/backports/1.9.1/symbol/comparable.rb +7 -0
  285. data/lib/backports/1.9.1/symbol/comparison.rb +8 -0
  286. data/lib/backports/1.9.1/symbol/downcase.rb +7 -0
  287. data/lib/backports/1.9.1/symbol/element_reference.rb +7 -0
  288. data/lib/backports/1.9.1/symbol/empty.rb +7 -0
  289. data/lib/backports/1.9.1/symbol/length.rb +7 -0
  290. data/lib/backports/1.9.1/symbol/match.rb +9 -0
  291. data/lib/backports/1.9.1/symbol/next.rb +1 -0
  292. data/lib/backports/1.9.1/symbol/size.rb +7 -0
  293. data/lib/backports/1.9.1/symbol/succ.rb +8 -0
  294. data/lib/backports/1.9.1/symbol/swapcase.rb +7 -0
  295. data/lib/backports/1.9.1/symbol/upcase.rb +7 -0
  296. data/lib/backports/1.9.2.rb +2 -4
  297. data/lib/backports/1.9.2/array.rb +2 -109
  298. data/lib/backports/1.9.2/array/keep_if.rb +8 -0
  299. data/lib/backports/1.9.2/array/product.rb +26 -0
  300. data/lib/backports/1.9.2/array/repeated_combination.rb +25 -0
  301. data/lib/backports/1.9.2/array/repeated_permutation.rb +26 -0
  302. data/lib/backports/1.9.2/array/rotate.rb +17 -0
  303. data/lib/backports/1.9.2/array/select.rb +8 -0
  304. data/lib/backports/1.9.2/array/sort_by.rb +9 -0
  305. data/lib/backports/1.9.2/array/uniq.rb +29 -0
  306. data/lib/backports/1.9.2/complex.rb +3 -6
  307. data/lib/backports/1.9.2/complex/to_r.rb +10 -0
  308. data/lib/backports/1.9.2/dir.rb +3 -5
  309. data/lib/backports/1.9.2/dir/home.rb +5 -0
  310. data/lib/backports/1.9.2/enumerable.rb +2 -73
  311. data/lib/backports/1.9.2/enumerable/chunk.rb +39 -0
  312. data/lib/backports/1.9.2/enumerable/collect_concat.rb +1 -0
  313. data/lib/backports/1.9.2/enumerable/each_entry.rb +11 -0
  314. data/lib/backports/1.9.2/enumerable/flat_map.rb +11 -0
  315. data/lib/backports/1.9.2/enumerable/slice_before.rb +30 -0
  316. data/lib/backports/1.9.2/float.rb +3 -4
  317. data/lib/backports/1.9.2/float/infinity.rb +3 -0
  318. data/lib/backports/1.9.2/float/nan.rb +3 -0
  319. data/lib/backports/1.9.2/hash.rb +2 -10
  320. data/lib/backports/1.9.2/hash/keep_if.rb +8 -0
  321. data/lib/backports/1.9.2/hash/select.rb +9 -0
  322. data/lib/backports/1.9.2/kernel.rb +3 -5
  323. data/lib/backports/1.9.2/kernel/singleton_class.rb +7 -0
  324. data/lib/backports/1.9.2/random.rb +1 -1
  325. data/lib/backports/1.9.2/stdlib.rb +1 -1
  326. data/lib/backports/1.9.2/stdlib/matrix.rb +9 -8
  327. data/lib/backports/1.9.2/stdlib/set.rb +1 -1
  328. data/lib/backports/1.9.3.rb +2 -4
  329. data/lib/backports/1.9.3/file.rb +3 -14
  330. data/lib/backports/1.9.3/file/null.rb +16 -0
  331. data/lib/backports/1.9.3/io.rb +2 -31
  332. data/lib/backports/1.9.3/io/advise.rb +24 -0
  333. data/lib/backports/1.9.3/io/binwrite.rb +7 -0
  334. data/lib/backports/1.9.3/io/write.rb +7 -0
  335. data/lib/backports/1.9.3/string.rb +2 -38
  336. data/lib/backports/1.9.3/string/byteslice.rb +36 -0
  337. data/lib/backports/1.9.3/string/prepend.rb +10 -0
  338. data/lib/backports/1.9.rb +1 -3
  339. data/lib/backports/2.0.0.rb +2 -4
  340. data/lib/backports/2.0.0/array.rb +2 -29
  341. data/lib/backports/2.0.0/array/bsearch.rb +32 -0
  342. data/lib/backports/2.0.0/enumerable.rb +2 -11
  343. data/lib/backports/2.0.0/enumerable/lazy.rb +216 -0
  344. data/lib/backports/2.0.0/enumerator.rb +3 -0
  345. data/lib/backports/2.0.0/enumerator/lazy.rb +1 -203
  346. data/lib/backports/2.0.0/env.rb +3 -0
  347. data/lib/backports/2.0.0/env/to_h.rb +5 -0
  348. data/lib/backports/2.0.0/hash.rb +2 -18
  349. data/lib/backports/2.0.0/hash/default_proc.rb +16 -0
  350. data/lib/backports/2.0.0/hash/to_h.rb +7 -0
  351. data/lib/backports/2.0.0/nil.rb +3 -0
  352. data/lib/backports/2.0.0/nil/to_h.rb +7 -0
  353. data/lib/backports/2.0.0/range.rb +2 -48
  354. data/lib/backports/2.0.0/range/bsearch.rb +49 -0
  355. data/lib/backports/2.0.0/stdlib/abbrev.rb +1 -0
  356. data/lib/backports/2.0.0/stdlib/fake_stdlib_lib.rb +1 -0
  357. data/lib/backports/2.0.0/stdlib/ostruct.rb +1 -1
  358. data/lib/backports/2.0.0/struct.rb +3 -7
  359. data/lib/backports/2.0.0/struct/to_h.rb +9 -0
  360. data/lib/backports/2.0.rb +1 -3
  361. data/lib/backports/basic_object.rb +29 -29
  362. data/lib/backports/{1.9.2 → extra}/random/MT19937.rb +2 -2
  363. data/lib/backports/{1.9.2 → extra}/random/bits_and_bytes.rb +1 -1
  364. data/lib/backports/{1.9.2 → extra}/random/implementation.rb +1 -1
  365. data/lib/backports/extra/random/load.rb +17 -0
  366. data/lib/backports/force/array_map.rb +1 -1
  367. data/lib/backports/force/enumerable_map.rb +1 -1
  368. data/lib/backports/force/hash_select.rb +1 -1
  369. data/lib/backports/force/string_size.rb +1 -1
  370. data/lib/backports/rails.rb +2 -2
  371. data/lib/backports/rails/enumerable.rb +1 -1
  372. data/lib/backports/rails/hash.rb +1 -1
  373. data/lib/backports/rails/kernel.rb +1 -1
  374. data/lib/backports/rails/module.rb +1 -1
  375. data/lib/backports/rails/string.rb +6 -6
  376. data/lib/backports/tools.rb +74 -64
  377. data/lib/backports/version.rb +1 -1
  378. data/set_version/1.8.7.rb +1 -0
  379. data/set_version/1.9.1.rb +1 -0
  380. data/set_version/1.9.2.rb +1 -0
  381. data/set_version/1.9.3.rb +1 -0
  382. data/set_version/2.0.0.rb +1 -0
  383. data/set_version/setter.rb +14 -0
  384. data/tags/1.8.6/core/array/rotate_spec.rb +2 -0
  385. data/tags/1.8.6/core/array/uniq_spec.rb +3 -0
  386. data/tags/1.8.6/core/complex/to_r_spec.rb +3 -0
  387. data/tags/1.8.6/core/enumerable/each_entry_spec.rb +1 -0
  388. data/tags/1.8.6/core/enumerator/next_spec.rb +1 -0
  389. data/tags/1.8.6/core/env/to_h_spec.rb +2 -0
  390. data/tags/1.8.6/core/file/join_spec.rb +3 -0
  391. data/tags/1.8.6/core/file/lchmod_spec.rb +2 -0
  392. data/tags/1.8.6/core/file/new_spec.rb +2 -0
  393. data/tags/1.8.6/core/file/open_spec.rb +10 -0
  394. data/tags/1.8.6/core/file/to_path_spec.rb +1 -0
  395. data/tags/1.8.6/core/fixnum/fdiv_spec.rb +1 -0
  396. data/tags/1.8.6/core/gc/stress_spec.rb +2 -0
  397. data/tags/1.8.6/core/hash/assoc_spec.rb +1 -0
  398. data/tags/1.8.6/core/hash/default_proc_spec.rb +2 -0
  399. data/tags/1.8.6/core/hash/eql_spec.rb +3 -0
  400. data/tags/1.8.6/core/hash/hash_spec.rb +3 -0
  401. data/tags/1.8.6/core/hash/keep_if_spec.rb +1 -0
  402. data/tags/1.8.6/core/hash/select_spec.rb +1 -0
  403. data/tags/1.8.6/core/integer/round_spec.rb +1 -0
  404. data/tags/1.8.6/core/io/binread_spec.rb +7 -0
  405. data/tags/1.8.6/core/io/chars_spec.rb +1 -0
  406. data/tags/1.8.6/core/io/each_char_spec.rb +1 -0
  407. data/tags/1.8.6/core/io/lines_spec.rb +1 -0
  408. data/tags/1.8.6/core/io/open_spec.rb +24 -0
  409. data/tags/1.8.6/core/io/ungetbyte_spec.rb +4 -0
  410. data/tags/1.8.6/core/io/write_spec.rb +3 -0
  411. data/tags/1.8.6/core/kernel/__callee___spec.rb +5 -0
  412. data/tags/1.8.6/core/kernel/__method___spec.rb +1 -0
  413. data/tags/1.8.6/core/kernel/define_singleton_method_spec.rb +2 -0
  414. data/tags/1.8.6/core/kernel/public_method_spec.rb +2 -0
  415. data/tags/1.8.6/core/math/log2_spec.rb +4 -0
  416. data/tags/1.8.6/core/math/log_spec.rb +3 -0
  417. data/tags/1.8.6/core/module/class_exec_spec.rb +2 -0
  418. data/tags/1.8.6/core/module/module_exec_spec.rb +2 -0
  419. data/tags/1.8.6/core/numeric/step_spec.rb +12 -0
  420. data/tags/1.8.6/core/proc/curry_spec.rb +4 -0
  421. data/tags/1.8.6/core/range/step_spec.rb +12 -0
  422. data/tags/1.8.6/core/string/getbyte_spec.rb +6 -0
  423. data/tags/1.8.6/core/string/partition_spec.rb +1 -0
  424. data/tags/1.8.6/core/string/prepend_spec.rb +1 -0
  425. data/tags/1.8.6/core/string/rpartition_spec.rb +1 -0
  426. data/tags/1.8.6/core/string/setbyte_spec.rb +5 -0
  427. data/tags/1.8.6/core/string/upto_spec.rb +1 -0
  428. data/tags/1.8.6/core/symbol/capitalize_spec.rb +3 -0
  429. data/tags/1.8.6/core/symbol/comparison_spec.rb +1 -0
  430. data/tags/1.8.6/core/symbol/downcase_spec.rb +2 -0
  431. data/tags/1.8.6/core/symbol/element_reference_spec.rb +2 -0
  432. data/tags/1.8.6/core/symbol/empty_spec.rb +1 -0
  433. data/tags/1.8.6/core/symbol/match_spec.rb +2 -0
  434. data/tags/1.8.6/core/symbol/swapcase_spec.rb +2 -0
  435. data/tags/1.8.6/core/symbol/upcase_spec.rb +1 -0
  436. data/tags/1.8.7/core/array/rotate_spec.rb +2 -0
  437. data/tags/1.8.7/core/array/uniq_spec.rb +3 -0
  438. data/tags/1.8.7/core/complex/to_r_spec.rb +3 -0
  439. data/tags/1.8.7/core/env/to_h_spec.rb +2 -0
  440. data/tags/1.8.7/core/file/lchmod_spec.rb +2 -0
  441. data/tags/1.8.7/core/file/new_spec.rb +1 -0
  442. data/tags/1.8.7/core/file/open_spec.rb +1 -0
  443. data/tags/1.8.7/core/file/readlink_spec.rb +6 -0
  444. data/tags/1.8.7/core/file/to_path_spec.rb +1 -0
  445. data/tags/1.8.7/core/hash/assoc_spec.rb +1 -0
  446. data/tags/1.8.7/core/hash/default_proc_spec.rb +2 -0
  447. data/tags/1.8.7/core/hash/keep_if_spec.rb +1 -0
  448. data/tags/1.8.7/core/hash/rassoc_spec.rb +1 -0
  449. data/tags/1.8.7/core/hash/select_spec.rb +1 -0
  450. data/tags/1.8.7/core/integer/round_spec.rb +1 -0
  451. data/tags/1.8.7/core/io/binread_spec.rb +7 -0
  452. data/tags/1.8.7/core/io/open_spec.rb +25 -0
  453. data/tags/1.8.7/core/io/ungetbyte_spec.rb +4 -0
  454. data/tags/1.8.7/core/io/write_spec.rb +3 -0
  455. data/tags/1.8.7/core/kernel/__callee___spec.rb +5 -0
  456. data/tags/1.8.7/core/kernel/define_singleton_method_spec.rb +2 -0
  457. data/tags/1.8.7/core/kernel/public_method_spec.rb +1 -0
  458. data/tags/1.8.7/core/math/log2_spec.rb +4 -0
  459. data/tags/1.8.7/core/math/log_spec.rb +3 -0
  460. data/tags/1.8.7/core/proc/curry_spec.rb +3 -0
  461. data/tags/1.8.7/core/string/getbyte_spec.rb +5 -0
  462. data/tags/1.8.7/core/string/prepend_spec.rb +1 -0
  463. data/tags/1.8.7/core/string/setbyte_spec.rb +5 -0
  464. data/tags/1.8.7/core/symbol/capitalize_spec.rb +3 -0
  465. data/tags/1.8.7/core/symbol/comparison_spec.rb +1 -0
  466. data/tags/1.8.7/core/symbol/downcase_spec.rb +2 -0
  467. data/tags/1.8.7/core/symbol/element_reference_spec.rb +2 -0
  468. data/tags/1.8.7/core/symbol/empty_spec.rb +1 -0
  469. data/tags/1.8.7/core/symbol/match_spec.rb +2 -0
  470. data/tags/1.8.7/core/symbol/swapcase_spec.rb +2 -0
  471. data/tags/1.8.7/core/symbol/upcase_spec.rb +1 -0
  472. data/tags/1.9.1/core/array/rotate_spec.rb +1 -0
  473. data/tags/1.9.1/core/env/to_h_spec.rb +2 -0
  474. data/tags/1.9.1/core/hash/default_proc_spec.rb +1 -0
  475. data/tags/1.9.1/core/io/write_spec.rb +2 -0
  476. data/tags/1.9.2/core/io/write_spec.rb +2 -0
  477. data/test/README +1 -1
  478. data/test/_backport_guards_test.rb +140 -0
  479. data/test/{test_lazy.rb → lazy_test.rb} +25 -20
  480. data/test/{test_socket_interaction.rb → socket_interaction_test.rb} +3 -3
  481. data/test/test_helper.rb +0 -4
  482. metadata +392 -16
  483. data/lib/backports/1.9.2/match_data.rb +0 -3
  484. data/lib/backports/1.9.2/random/load.rb +0 -16
  485. data/lib/backports/2.0.0/nil_class.rb +0 -5
  486. data/test/std_lib_loading_test.rb +0 -57
  487. data/test/test__me_first.rb +0 -51
@@ -12,7 +12,7 @@ class Random
12
12
 
13
13
  LAST_31_BITS = 0x7fffffff
14
14
  OFFSET = 397
15
-
15
+
16
16
  # Generates a completely new state out of the previous one.
17
17
  def next_state
18
18
  STATE_SIZE.times do |i|
@@ -73,4 +73,4 @@ class Random
73
73
  y ^= (y >> 18)
74
74
  end
75
75
  end
76
- end
76
+ end
@@ -88,4 +88,4 @@ class Random
88
88
  n
89
89
  end
90
90
  end
91
- end
91
+ end
@@ -90,4 +90,4 @@ class Random
90
90
  Kernel::srand # use the built-in seed generator
91
91
  Kernel::srand # return the generated seed
92
92
  end
93
- end
93
+ end
@@ -0,0 +1,17 @@
1
+ require "backports/tools"
2
+ require "backports/extra/random/MT19937"
3
+ require "backports/extra/random/bits_and_bytes"
4
+ require "backports/extra/random/implementation"
5
+
6
+ class Random
7
+ include Implementation
8
+ class << self
9
+ include Implementation
10
+ end
11
+
12
+ def inspect
13
+ "#<#{self.class.name}:#{object_id}>"
14
+ end
15
+
16
+ srand
17
+ end
@@ -1 +1 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/enumerable_map")
1
+ require 'backports/force/enumerable_map'
@@ -1,3 +1,3 @@
1
1
  Backports.make_block_optional Enumerable, :map, :test_on => 1..2
2
2
  Backports.make_block_optional Array, :map, :test_on => [1, 2]
3
-
3
+
@@ -6,4 +6,4 @@ class Hash
6
6
  end
7
7
  Backports.alias_method_chain self, :select, :hash_return
8
8
  end
9
- end
9
+ end
@@ -1 +1 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/string_length")
1
+ require 'backports/force/string_length'
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/tools")
1
+ require "backports/tools"
2
2
  %w(array enumerable hash kernel module string).each do |lib|
3
- Backports.require_relative "rails/#{lib}"
3
+ require "backports/rails/#{lib}"
4
4
  end
@@ -9,4 +9,4 @@ module Enumerable
9
9
  end
10
10
  end unless method_defined? :sum
11
11
 
12
- end
12
+ end
@@ -28,4 +28,4 @@ class Hash
28
28
  def stringify_keys!
29
29
  self.replace(self.stringify_keys)
30
30
  end unless method_defined? :stringify_keys!
31
- end
31
+ end
@@ -9,4 +9,4 @@ module Kernel
9
9
  yield obj
10
10
  obj
11
11
  end unless method_defined? :returning
12
- end
12
+ end
@@ -3,4 +3,4 @@ class Module
3
3
  def alias_method_chain(target, feature)
4
4
  Backports.alias_method_chain(self, target, feature)
5
5
  end unless method_defined? :alias_method_chain
6
- end
6
+ end
@@ -1,6 +1,6 @@
1
1
  class String
2
2
  # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
3
- def camelize(first_letter = :upper)
3
+ def camelize(first_letter = :upper)
4
4
  if first_letter == :upper
5
5
  gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
6
6
  else
@@ -12,19 +12,19 @@ class String
12
12
  def constantize
13
13
  names = split('::')
14
14
  names.shift if names.empty? || names.first.empty?
15
-
15
+
16
16
  constant = Object
17
17
  names.each do |name|
18
18
  constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
19
19
  end
20
20
  constant
21
21
  end unless method_defined? :constantize
22
-
22
+
23
23
  # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
24
24
  def dasherize
25
25
  gsub(/_/, '-')
26
26
  end unless method_defined? :dasherize
27
-
27
+
28
28
  # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
29
29
  def demodulize
30
30
  gsub(/^.*::/, '')
@@ -38,5 +38,5 @@ class String
38
38
  tr("-", "_").
39
39
  downcase
40
40
  end unless method_defined? :underscore
41
-
42
- end
41
+
42
+ end
@@ -1,22 +1,25 @@
1
1
  # Methods used internally by the backports.
2
2
  module Backports
3
- # Adapted from Pragmatic's "Programming Ruby" (since their version was buggy...)
4
- def self.require_relative(relative_feature)
5
- file = caller.first.split(/:\d/,2).first
6
- if /\A\((.*)\)/ =~ file # eval, etc.
7
- raise LoadError, "require_relative is called in #{$1}"
3
+ MOST_EXTREME_OBJECT_EVER = Object.new # :nodoc:
4
+ class << MOST_EXTREME_OBJECT_EVER
5
+ def < (whatever)
6
+ true
7
+ end
8
+
9
+ def > (whatever)
10
+ true
8
11
  end
9
- require File.expand_path(relative_feature, File.dirname(file))
10
12
  end
11
13
 
12
- def self.require_relative_dir(relative_dir)
13
- dir = File.expand_path(relative_dir, File.dirname(caller.first.split(/:\d/,2).first))
14
+ def self.require_relative_dir
15
+ dir = caller.first.split(/\.rb:\d/,2).first
16
+ short_path = dir[/.*(backports\/.*)/, 1] << '/'
14
17
  Dir.entries(dir).
15
18
  map{|f| Regexp.last_match(1) if /^(.*)\.rb$/ =~ f}.
16
19
  compact.
17
20
  sort.
18
21
  each do |f|
19
- require File.expand_path(f, dir)
22
+ require short_path + f
20
23
  end
21
24
  end
22
25
 
@@ -24,13 +27,12 @@ module Backports
24
27
  class LoadedFeatures
25
28
  if RUBY_VERSION >= "1.9"
26
29
  # Full paths are recorded in $LOADED_FEATURES.
27
- def initialize
28
- # Assume backported features are Ruby libraries (i.e. not C)
29
- @loaded = $LOADED_FEATURES.group_by{|p| File.basename(p, ".rb")}
30
- end
31
-
30
+ @@our_loads = {}
32
31
  # Check loaded features for one that matches "#{any of the load path}/#{feature}"
33
32
  def include?(feature)
33
+ return true if @@our_loads[feature]
34
+ # Assume backported features are Ruby libraries (i.e. not C)
35
+ @loaded ||= $LOADED_FEATURES.group_by{|p| File.basename(p, ".rb")}
34
36
  if fullpaths = @loaded[File.basename(feature, ".rb")]
35
37
  fullpaths.any?{|fullpath|
36
38
  base_dir, = fullpath.partition("/#{feature}")
@@ -40,6 +42,7 @@ module Backports
40
42
  end
41
43
 
42
44
  def self.mark_as_loaded(feature)
45
+ @@our_loads[feature] = true
43
46
  # Nothing to do, the full path will be OK
44
47
  end
45
48
 
@@ -81,6 +84,7 @@ module Backports
81
84
  # Metaprogramming utility to make block optional.
82
85
  # Tests first if block is already optional when given options
83
86
  def self.make_block_optional(mod, *methods)
87
+ mod = class << mod; self; end unless mod.is_a? Module
84
88
  options = methods.last.is_a?(Hash) ? methods.pop : {}
85
89
  methods.each do |selector|
86
90
  unless mod.method_defined? selector
@@ -97,6 +101,7 @@ module Backports
97
101
  end
98
102
  next if result.class.name =~ /Enumerator$/
99
103
  end
104
+ require 'enumerator'
100
105
  arity = mod.instance_method(selector).arity
101
106
  last_arg = []
102
107
  if arity < 0
@@ -106,7 +111,7 @@ module Backports
106
111
  arg_sequence = ((0...arity).map{|i| "arg_#{i}"} + last_arg + ["&block"]).join(", ")
107
112
 
108
113
  alias_method_chain(mod, selector, :optional_block) do |aliased_target, punctuation|
109
- mod.module_eval <<-end_eval
114
+ mod.module_eval <<-end_eval, __FILE__, __LINE__ + 1
110
115
  def #{aliased_target}_with_optional_block#{punctuation}(#{arg_sequence})
111
116
  return to_enum(:#{aliased_target}_without_optional_block#{punctuation}, #{arg_sequence}) unless block_given?
112
117
  #{aliased_target}_without_optional_block#{punctuation}(#{arg_sequence})
@@ -117,52 +122,54 @@ module Backports
117
122
  end
118
123
 
119
124
  # Metaprogramming utility to convert the first file argument to path
120
- def self.convert_first_argument_to_path(mod, *methods)
121
- methods.each do |selector|
122
- unless mod.method_defined? selector
123
- warn "#{mod}##{selector} is not defined, so argument can't converted to path"
124
- next
125
- end
126
- arity = mod.instance_method(selector).arity
127
- last_arg = []
128
- if arity < 0
129
- last_arg = ["*rest"]
130
- arity = -1-arity
131
- end
132
- arg_sequence = (["file"] + (1...arity).map{|i| "arg_#{i}"} + last_arg + ["&block"]).join(", ")
125
+ def self.convert_first_argument_to_path(klass, selector)
126
+ mod = class << klass; self; end
127
+ unless mod.method_defined? selector
128
+ warn "#{mod}##{selector} is not defined, so argument can't converted to path"
129
+ return
130
+ end
131
+ arity = mod.instance_method(selector).arity
132
+ last_arg = []
133
+ if arity < 0
134
+ last_arg = ["*rest"]
135
+ arity = -1-arity
136
+ end
137
+ arg_sequence = (["file"] + (1...arity).map{|i| "arg_#{i}"} + last_arg + ["&block"]).join(", ")
133
138
 
134
- alias_method_chain(mod, selector, :potential_path_argument) do |aliased_target, punctuation|
135
- mod.module_eval <<-end_eval
136
- def #{aliased_target}_with_potential_path_argument#{punctuation}(#{arg_sequence})
137
- file = Backports.convert_to_path(file)
138
- #{aliased_target}_without_potential_path_argument#{punctuation}(#{arg_sequence})
139
- end
140
- end_eval
141
- end
139
+ alias_method_chain(mod, selector, :potential_path_argument) do |aliased_target, punctuation|
140
+ mod.module_eval <<-end_eval, __FILE__, __LINE__ + 1
141
+ def #{aliased_target}_with_potential_path_argument#{punctuation}(#{arg_sequence})
142
+ file = Backports.convert_path(file)
143
+ #{aliased_target}_without_potential_path_argument#{punctuation}(#{arg_sequence})
144
+ end
145
+ end_eval
142
146
  end
143
147
  end
144
148
 
145
149
  # Metaprogramming utility to convert all file arguments to paths
146
- def self.convert_all_arguments_to_path(mod, skip, *methods)
147
- methods.each do |selector|
148
- unless mod.method_defined? selector
149
- warn "#{mod}##{selector} is not defined, so arguments can't converted to path"
150
- next
151
- end
152
- first_args = (1..skip).map{|i| "arg_#{i}"}.join(",") + (skip > 0 ? "," : "")
153
- alias_method_chain(mod, selector, :potential_path_arguments) do |aliased_target, punctuation|
154
- mod.module_eval <<-end_eval
155
- def #{aliased_target}_with_potential_path_arguments#{punctuation}(#{first_args}*files, &block)
156
- files = files.map{|f| Backports.convert_to_path f}
157
- #{aliased_target}_without_potential_path_arguments#{punctuation}(#{first_args}*files, &block)
158
- end
159
- end_eval
160
- end
150
+ def self.convert_all_arguments_to_path(klass, selector, skip)
151
+ mod = class << klass; self; end
152
+ unless mod.method_defined? selector
153
+ warn "#{mod}##{selector} is not defined, so arguments can't converted to path"
154
+ return
155
+ end
156
+ first_args = (1..skip).map{|i| "arg_#{i}"}.join(",") + (skip > 0 ? "," : "")
157
+ alias_method_chain(mod, selector, :potential_path_arguments) do |aliased_target, punctuation|
158
+ mod.module_eval <<-end_eval, __FILE__, __LINE__ + 1
159
+ def #{aliased_target}_with_potential_path_arguments#{punctuation}(#{first_args}*files, &block)
160
+ files = files.map{|f| Backports.convert_path(f) }
161
+ #{aliased_target}_without_potential_path_arguments#{punctuation}(#{first_args}*files, &block)
162
+ end
163
+ end_eval
161
164
  end
162
165
  end
163
166
 
164
- def self.convert_to_path(file_or_path)
165
- file_or_path.respond_to?(:to_path) ? file_or_path.to_path : file_or_path
167
+ def self.convert_path(path)
168
+ try_convert(path, IO, :to_io) ||
169
+ begin
170
+ path = path.to_path if path.respond_to?(:to_path)
171
+ try_convert(path, String, :to_str) || path
172
+ end
166
173
  end
167
174
 
168
175
  # Modified to avoid polluting Module if so desired
@@ -253,23 +260,17 @@ module Backports
253
260
  end
254
261
  end
255
262
 
256
- # Used internally to propagate #lambda?
257
- def self.track_lambda(from, to, default = false)
258
- is_lambda = from.instance_variable_get :@is_lambda
259
- is_lambda = default if is_lambda.nil?
260
- to.instance_variable_set :@is_lambda, is_lambda
261
- to
262
- end
263
-
264
263
  # Used internally to combine {IO|File} options hash into mode (String or Integer)
265
264
  def self.combine_mode_and_option(mode = nil, options = Backports::Undefined)
266
265
  # Can't backport autoclose, {internal|external|}encoding
267
- mode, options = nil, mode if mode.is_a?(Hash) and options == Backports::Undefined
268
- options = {} if options == Backports::Undefined
266
+ mode, options = nil, mode if mode.respond_to?(:to_hash) and options == Backports::Undefined
267
+ options = {} if options == nil || options == Backports::Undefined
268
+ options = coerce_to(options, Hash, :to_hash)
269
269
  if mode && options[:mode]
270
270
  raise ArgumentError, "mode specified twice"
271
271
  end
272
272
  mode ||= options[:mode] || "r"
273
+ mode = try_convert(mode, String, :to_str) || try_convert(mode, Integer, :to_int) || mode
273
274
  if options[:textmode] || options[:binmode]
274
275
  text = options[:textmode] || (mode.is_a?(String) && mode =~ /t/)
275
276
  bin = options[:binmode] || (mode.is_a?(String) ? mode =~ /b/ : mode & File::Constants::BINARY != 0)
@@ -302,14 +303,23 @@ module Backports
302
303
  def self.write(binary, filename, string, offset, options)
303
304
  offset, options = nil, offset if Hash === offset and options == Backports::Undefined
304
305
  options = {} if options == Backports::Undefined
306
+ File.open(filename, 'a+'){} if offset # insure existence
305
307
  options = {:mode => offset.nil? ? "w" : "r+"}.merge(options)
306
308
  args = options[:open_args] || [options]
307
- File.open(filename, *args) do |f|
309
+ File.open(filename, *Backports.combine_mode_perm_and_option(*args)) do |f|
308
310
  f.binmode if binary && f.respond_to?(:binmode)
309
311
  f.seek(offset) unless offset.nil?
310
312
  f.write(string)
311
313
  end
312
314
  end
315
+
316
+ def self.suppress_verbose_warnings
317
+ before = $VERBOSE
318
+ $VERBOSE = false if $VERBOSE # Set to false (default warning) but not nil (no warnings)
319
+ yield
320
+ ensure
321
+ $VERBOSE = before
322
+ end
313
323
  end
314
324
 
315
325
  module Kernel
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.0.3"
2
+ VERSION = "3.1.0" unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
3
3
  end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/setter")
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/setter")
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/setter")
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/setter")
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/setter")
@@ -0,0 +1,14 @@
1
+ module Backports
2
+ TARGET_VERSION = caller.each{|c| break $1 if c =~ /set_version\/(\d\.\d\.\d)\.rb/}
3
+ end
4
+
5
+ unless Object.const_defined?(:Enumerator) || Backports::TARGET_VERSION < '1.9'
6
+ require 'enumerator'
7
+ # Needed for mspec:
8
+ Enumerator = Enumerable::Enumerator
9
+ end
10
+
11
+ if RUBY_VERSION < Backports::TARGET_VERSION && Backports::TARGET_VERSION >= '1.9'
12
+ require 'backports/1.9.2/float/infinity.rb' # Used in many specs...
13
+ require 'backports/1.9.2/float/nan.rb' # Used in many specs...
14
+ end
@@ -0,0 +1,2 @@
1
+ fails:Array#rotate returns subclass instance for Array subclasses
2
+ fails:Array#rotate! raises a RuntimeError on a frozen array
@@ -0,0 +1,3 @@
1
+ fails:Array#uniq! raises a RuntimeError on a frozen array when the array is modified
2
+ fails:Array#uniq! raises a RuntimeError on a frozen array when the array would not be modified
3
+ fails:Array#uniq! doesn't yield to the block on a frozen array
@@ -0,0 +1,3 @@
1
+ fails:Complex#to_r when the imaginary part is Fixnum 0 returns the result of sending #to_r to the real part
2
+ fails:Complex#to_r when the imaginary part is Rational 0 returns the result of sending #to_r to the real part
3
+ fails:Complex#to_r when the imaginary part responds to #== 0 with true returns the result of sending #to_r to the real part
@@ -0,0 +1 @@
1
+ fails:Enumerable#each_entry passes through the values yielded by #each_with_index
@@ -0,0 +1 @@
1
+ fails:Enumerator#next is rewound after encountering a StopIteration
@@ -0,0 +1,2 @@
1
+ fails:ENV.to_hash uses the locale encoding for keys
2
+ fails:ENV.to_hash uses the locale encoding for values
@@ -0,0 +1,3 @@
1
+ fails:File.join flattens nested arrays
2
+ fails:File.join inserts the separator in between empty strings and arrays
3
+ fails:File.join raises an ArgumentError if passed a recursive array
@@ -0,0 +1,2 @@
1
+ fails:File.lchmod returns false from #respond_to?
2
+ fails:File.lchmod raises a NotImplementedError when called
@@ -0,0 +1,2 @@
1
+ fails:File.new returns a new File when use File::APPEND mode
2
+ fails:File.new returns a new File when use File::RDONLY|File::APPEND mode
@@ -0,0 +1,10 @@
1
+ fails:File.open on a FIFO opens it as a normal file
2
+ fails:File.open opens file when call with a block (basic case)
3
+ fails:File.open opens a file with mode string and block
4
+ fails:File.open opens a file with mode num and block
5
+ fails:File.open opens the file when passed mode, num, permissions and block
6
+ fails:File.open opens the file when call with fd
7
+ fails:File.open opens a file with a file descriptor d and a block
8
+ fails:File.open raises a SystemCallError if passed an invalid Integer type
9
+ fails:File.open raises an IOError when read in a block opened with File::RDONLY|File::APPEND mode
10
+ fails:File.open raises an IOError if the file exists when open with File::RDONLY|File::APPEND