facets 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (321) hide show
  1. data/HISTORY.rdoc +331 -35
  2. data/MANIFEST +685 -826
  3. data/{doc/guide/notes.rd → NOTES} +0 -0
  4. data/README.rdoc +73 -25
  5. data/Rakefile +245 -2
  6. data/TODO +5 -0
  7. data/demo/hook.rd +47 -0
  8. data/demo/scenario_require.rd +9 -0
  9. data/doc/README.more +24 -6
  10. data/doc/manual/about.rb +47 -0
  11. data/doc/manual/annotations.rdoc +60 -0
  12. data/doc/manual/associations.rdoc +55 -0
  13. data/doc/manual/blockups.rdoc +101 -0
  14. data/doc/manual/capsule.rdoc +34 -0
  15. data/doc/manual/command.rdoc +177 -0
  16. data/doc/manual/core.rdoc +37 -0
  17. data/doc/manual/faq.rdoc +32 -0
  18. data/doc/manual/typecast.html +112 -0
  19. data/lib/core/facets.rb +359 -11
  20. data/lib/core/facets/array/combination.rb +3 -3
  21. data/lib/core/facets/array/index.rb +4 -1
  22. data/lib/core/facets/array/permutation.rb +2 -2
  23. data/lib/core/facets/array/product.rb +1 -1
  24. data/lib/core/facets/binding/eval.rb +1 -1
  25. data/lib/core/facets/denumerable.rb +76 -0
  26. data/lib/core/facets/duplicable.rb +34 -0
  27. data/lib/core/facets/enumerable/count.rb +10 -4
  28. data/lib/core/facets/enumerable/defer.rb +77 -0
  29. data/lib/core/facets/enumerable/each_by.rb +1 -1
  30. data/lib/core/facets/enumerable/every.rb +35 -0
  31. data/lib/{more/facets/elementwise.rb → core/facets/enumerable/ewise.rb} +0 -0
  32. data/lib/core/facets/enumerable/filter.rb +25 -0
  33. data/lib/core/facets/enumerable/group_by.rb +1 -1
  34. data/lib/core/facets/enumerable/none.rb +3 -2
  35. data/lib/core/facets/enumerable/one.rb +3 -2
  36. data/lib/core/facets/enumerable/per.rb +61 -0
  37. data/lib/core/facets/exception/raised.rb +14 -0
  38. data/lib/core/facets/integer/odd.rb +5 -1
  39. data/lib/core/facets/kernel/__dir__.rb +13 -3
  40. data/lib/core/facets/kernel/__here__.rb +14 -0
  41. data/lib/core/facets/kernel/__method__.rb +9 -3
  42. data/lib/core/facets/kernel/ask.rb +1 -0
  43. data/lib/core/facets/kernel/equate.rb +13 -0
  44. data/lib/core/facets/kernel/extension.rb +9 -0
  45. data/lib/core/facets/kernel/identical.rb +4 -0
  46. data/lib/core/facets/kernel/instance_exec.rb +2 -1
  47. data/lib/core/facets/kernel/method.rb +49 -0
  48. data/lib/core/facets/kernel/object_send.rb +2 -2
  49. data/lib/core/facets/kernel/{state.rb → object_state.rb} +23 -12
  50. data/lib/core/facets/kernel/require_all.rb +6 -1
  51. data/lib/core/facets/kernel/require_local.rb +8 -1
  52. data/lib/core/facets/kernel/require_relative.rb +52 -0
  53. data/lib/core/facets/kernel/source_location.rb +13 -0
  54. data/lib/core/facets/kernel/tap.rb +13 -6
  55. data/lib/core/facets/module/attr_setter.rb +57 -0
  56. data/lib/core/facets/module/instance_method.rb +24 -0
  57. data/lib/core/facets/module/module_load.rb +60 -44
  58. data/lib/core/facets/module/module_require.rb +1 -0
  59. data/lib/core/facets/nilclass/to_f.rb +1 -1
  60. data/lib/core/facets/objectspace/op_fetch.rb +3 -0
  61. data/lib/core/facets/proc/curry.rb +4 -3
  62. data/lib/core/facets/string/bytes.rb +10 -4
  63. data/lib/core/facets/string/camelcase.rb +6 -5
  64. data/lib/core/facets/string/chars.rb +5 -1
  65. data/lib/core/facets/string/each_char.rb +1 -1
  66. data/lib/core/facets/string/each_word.rb +1 -1
  67. data/lib/core/facets/string/lines.rb +11 -4
  68. data/lib/core/facets/string/start_with.rb +9 -2
  69. data/lib/core/facets/string/unfold.rb +27 -0
  70. data/lib/core/facets/symbol/succ.rb +3 -3
  71. data/lib/core/facets/symbol/thrown.rb +20 -0
  72. data/lib/core/facets/symbol/to_proc.rb +3 -2
  73. data/lib/core/facets/time/to_time.rb +1 -1
  74. data/lib/core/facets/to_hash.rb +41 -100
  75. data/lib/core/facets/unboundmethod/name.rb +20 -23
  76. data/lib/more/facets/ansicode.rb +1 -10
  77. data/lib/more/facets/autoarray.rb +3 -31
  78. data/lib/more/facets/basicobject.rb +73 -0
  79. data/lib/more/facets/blankslate.rb +2 -66
  80. data/lib/{lore → more}/facets/cgi.rb +0 -0
  81. data/lib/more/facets/class_extend.rb +1 -0
  82. data/lib/{lore → more}/facets/continuation.rb +0 -0
  83. data/lib/{lore → more}/facets/date.rb +3 -3
  84. data/lib/more/facets/enumargs.rb +192 -0
  85. data/lib/more/facets/enumerablepass.rb +2 -216
  86. data/lib/more/facets/enumerator.rb +62 -0
  87. data/lib/more/facets/{equatable.rb → equitable.rb} +11 -11
  88. data/lib/more/facets/expirable.rb +13 -41
  89. data/lib/{lore → more}/facets/fileutils.rb +0 -0
  90. data/lib/{lore → more}/facets/fileutils/head.rb +0 -0
  91. data/lib/{lore → more}/facets/fileutils/safe_ln.rb +0 -0
  92. data/lib/{lore → more}/facets/fileutils/slice.rb +0 -0
  93. data/lib/{lore → more}/facets/fileutils/tail.rb +0 -0
  94. data/lib/{lore → more}/facets/fileutils/wc.rb +0 -0
  95. data/lib/{lore → more}/facets/fileutils/whereis.rb +0 -0
  96. data/lib/{lore → more}/facets/fileutils/which.rb +0 -0
  97. data/lib/{lore → more}/facets/getoptlong.rb +0 -0
  98. data/lib/more/facets/hook.rb +2 -29
  99. data/lib/more/facets/inheritor.rb +2 -2
  100. data/lib/more/facets/instance_eval.rb +50 -0
  101. data/lib/more/facets/instance_function.rb +78 -0
  102. data/lib/more/facets/main.rb +20 -15
  103. data/lib/more/facets/memoize.rb +1 -113
  104. data/lib/more/facets/module/attr.rb +83 -0
  105. data/lib/more/facets/module/attr_tester.rb +44 -0
  106. data/lib/more/facets/module/attr_toggler.rb +59 -0
  107. data/lib/more/facets/module/attr_validator.rb +34 -0
  108. data/lib/more/facets/{class_extension.rb → module/class_extend.rb} +21 -13
  109. data/lib/more/facets/once.rb +59 -0
  110. data/lib/more/facets/openmodule.rb +1 -0
  111. data/lib/more/facets/orderedhash.rb +1 -33
  112. data/lib/{lore → more}/facets/ostruct.rb +0 -0
  113. data/lib/more/facets/ostructable.rb +1 -4
  114. data/lib/more/facets/partial.rb +18 -16
  115. data/lib/{lore → more}/facets/pathname.rb +0 -0
  116. data/lib/more/facets/preinitialize.rb +157 -0
  117. data/lib/{lore → more}/facets/rbconfig.rb +0 -0
  118. data/lib/more/facets/recorder.rb +1 -2
  119. data/lib/{lore → more}/facets/set.rb +0 -0
  120. data/lib/{lore → more}/facets/shellwords.rb +0 -0
  121. data/lib/{lore → more}/facets/uri.rb +0 -0
  122. data/lib/{lore → more}/facets/yaml.rb +0 -0
  123. data/lib/{lore → more}/facets/zlib.rb +0 -0
  124. data/meta/loadpath +0 -1
  125. data/meta/sitemap +4 -0
  126. data/meta/version +1 -1
  127. data/test/core/enumerable/test_count.rb +1 -1
  128. data/test/{more/test_filter.rb → core/enumerable/test_defer.rb} +24 -22
  129. data/test/{more/test_elementor.rb → core/enumerable/test_every.rb} +2 -15
  130. data/test/core/enumerable/test_ewise.rb +23 -0
  131. data/test/core/enumerable/test_per.rb +18 -0
  132. data/test/core/enumerable/test_take.rb +13 -0
  133. data/test/core/kernel/test_deepcopy.rb +1 -1
  134. data/test/{more/test_1stclassmethod.rb → core/kernel/test_method.rb} +2 -7
  135. data/test/core/kernel/test_tap.rb +1 -1
  136. data/test/core/proc/test_curry.rb +11 -0
  137. data/test/core/string/test_bytes.rb +1 -1
  138. data/test/core/string/test_camelcase.rb +23 -6
  139. data/test/core/string/test_lines.rb +1 -1
  140. data/test/core/string/test_unfold.rb +14 -0
  141. data/test/{more → core}/test_blank.rb +0 -0
  142. data/test/{more → core}/test_boolean.rb +0 -0
  143. data/test/{more → core}/test_functor.rb +0 -0
  144. data/test/{lore → more}/test_basicobject.rb +0 -0
  145. data/test/more/{test_class_extension.rb → test_class_extend.rb} +6 -6
  146. data/test/{lore → more}/test_continuation.rb +0 -0
  147. data/test/{lore → more}/test_date.rb +0 -0
  148. data/test/more/{test_enumerablepass.rb → test_enumargs.rb} +2 -4
  149. data/test/more/{test_equatable.rb → test_equitable.rb} +2 -2
  150. data/test/more/{test_instantise.rb → test_instance_function.rb} +3 -2
  151. data/test/more/test_memoize.rb +1 -1
  152. data/test/{lore → more}/test_ostruct.rb +0 -0
  153. metadata +865 -1016
  154. data/RELEASE +0 -38
  155. data/doc/README.lore +0 -51
  156. data/doc/log/basic_stats/index.html +0 -39
  157. data/doc/log/changelog.html +0 -648
  158. data/doc/log/changelog.txt +0 -217
  159. data/doc/log/stats/index.html +0 -39
  160. data/doc/log/testlog.txt +0 -278
  161. data/doc/notes/CHANGES +0 -2529
  162. data/doc/rdoc/lore/classes/Array.html +0 -176
  163. data/doc/rdoc/lore/classes/CGI.html +0 -191
  164. data/doc/rdoc/lore/classes/Config.html +0 -135
  165. data/doc/rdoc/lore/classes/Continuation.html +0 -113
  166. data/doc/rdoc/lore/classes/Date.html +0 -631
  167. data/doc/rdoc/lore/classes/DateTime.html +0 -583
  168. data/doc/rdoc/lore/classes/Enumerable.html +0 -89
  169. data/doc/rdoc/lore/classes/Enumerable/Enumerator.html +0 -147
  170. data/doc/rdoc/lore/classes/File.html +0 -128
  171. data/doc/rdoc/lore/classes/FileUtils.html +0 -434
  172. data/doc/rdoc/lore/classes/GetoptLong.html +0 -118
  173. data/doc/rdoc/lore/classes/GetoptLong/DSL.html +0 -208
  174. data/doc/rdoc/lore/classes/Kernel.html +0 -135
  175. data/doc/rdoc/lore/classes/Logger.html +0 -229
  176. data/doc/rdoc/lore/classes/Logger/Ansicolor.html +0 -277
  177. data/doc/rdoc/lore/classes/Logger/LogDevice.html +0 -121
  178. data/doc/rdoc/lore/classes/NilClass.html +0 -119
  179. data/doc/rdoc/lore/classes/OpenStruct.html +0 -432
  180. data/doc/rdoc/lore/classes/Pathname.html +0 -353
  181. data/doc/rdoc/lore/classes/Set.html +0 -117
  182. data/doc/rdoc/lore/classes/Shellwords.html +0 -111
  183. data/doc/rdoc/lore/classes/String.html +0 -140
  184. data/doc/rdoc/lore/classes/Time.html +0 -154
  185. data/doc/rdoc/lore/classes/URI.html +0 -454
  186. data/doc/rdoc/lore/classes/URI/Hash.html +0 -105
  187. data/doc/rdoc/lore/classes/URI/Kernel.html +0 -122
  188. data/doc/rdoc/lore/classes/Zlib.html +0 -188
  189. data/doc/rdoc/lore/created.rid +0 -1
  190. data/doc/rdoc/lore/files/README.html +0 -286
  191. data/doc/rdoc/lore/files/doc/README_lore.html +0 -155
  192. data/doc/rdoc/lore/files/lib/lore/facets/basicobject_rb.html +0 -118
  193. data/doc/rdoc/lore/files/lib/lore/facets/cgi_rb.html +0 -111
  194. data/doc/rdoc/lore/files/lib/lore/facets/continuation_rb.html +0 -147
  195. data/doc/rdoc/lore/files/lib/lore/facets/date_rb.html +0 -97
  196. data/doc/rdoc/lore/files/lib/lore/facets/enumerator_rb.html +0 -111
  197. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/head_rb.html +0 -96
  198. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/safe_ln_rb.html +0 -96
  199. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/slice_rb.html +0 -96
  200. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/tail_rb.html +0 -96
  201. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/wc_rb.html +0 -96
  202. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/whereis_rb.html +0 -96
  203. data/doc/rdoc/lore/files/lib/lore/facets/fileutils/which_rb.html +0 -96
  204. data/doc/rdoc/lore/files/lib/lore/facets/fileutils_rb.html +0 -131
  205. data/doc/rdoc/lore/files/lib/lore/facets/getoptlong_rb.html +0 -135
  206. data/doc/rdoc/lore/files/lib/lore/facets/logger_rb.html +0 -142
  207. data/doc/rdoc/lore/files/lib/lore/facets/ostruct_rb.html +0 -135
  208. data/doc/rdoc/lore/files/lib/lore/facets/pathname_rb.html +0 -145
  209. data/doc/rdoc/lore/files/lib/lore/facets/rbconfig_rb.html +0 -124
  210. data/doc/rdoc/lore/files/lib/lore/facets/set_rb.html +0 -96
  211. data/doc/rdoc/lore/files/lib/lore/facets/shellwords_rb.html +0 -124
  212. data/doc/rdoc/lore/files/lib/lore/facets/uri_rb.html +0 -125
  213. data/doc/rdoc/lore/files/lib/lore/facets/yaml_rb.html +0 -146
  214. data/doc/rdoc/lore/files/lib/lore/facets/zlib_rb.html +0 -97
  215. data/doc/rdoc/lore/fr_class_index.html +0 -73
  216. data/doc/rdoc/lore/fr_file_index.html +0 -71
  217. data/doc/rdoc/lore/fr_method_index.html +0 -177
  218. data/doc/rdoc/lore/index.html +0 -26
  219. data/doc/rdoc/lore/rdoc-style.css +0 -177
  220. data/doc/release-notes/RELEASE-2.0.5 +0 -8
  221. data/doc/release-notes/RELEASE-2.1.0 +0 -9
  222. data/doc/release-notes/RELEASE-2.1.1 +0 -5
  223. data/doc/release-notes/RELEASE-2.1.2 +0 -6
  224. data/doc/release-notes/RELEASE-2.1.3 +0 -5
  225. data/doc/release-notes/RELEASE-2.2.0 +0 -14
  226. data/doc/release-notes/RELEASE-2.2.1 +0 -4
  227. data/doc/release-notes/RELEASE-2.3.0 +0 -6
  228. data/doc/release-notes/RELEASE-2.4.0 +0 -70
  229. data/doc/release-notes/RELEASE-2.4.1 +0 -8
  230. data/doc/release-notes/RELEASE-2.4.2 +0 -4
  231. data/doc/release-notes/RELEASE-2.4.3 +0 -78
  232. data/doc/release-notes/RELEASE-2.4.4 +0 -38
  233. data/doc/release-notes/RELEASE-2.4.5 +0 -37
  234. data/doc/release-notes/RELEASE-2.5.0 +0 -83
  235. data/lib/core/facets/kernel/instance.rb +0 -19
  236. data/lib/lore/facets/basicobject.rb +0 -14
  237. data/lib/lore/facets/enumerator.rb +0 -67
  238. data/lib/lore/facets/logger.rb +0 -291
  239. data/lib/more/facets/1stclassmethod.rb +0 -140
  240. data/lib/more/facets/advisable.rb +0 -162
  241. data/lib/more/facets/association.rb +0 -210
  242. data/lib/more/facets/attr.rb +0 -209
  243. data/lib/more/facets/basex.rb +0 -37
  244. data/lib/more/facets/bbcode.rb +0 -397
  245. data/lib/more/facets/bicrypt.rb +0 -265
  246. data/lib/more/facets/binreadable.rb +0 -221
  247. data/lib/more/facets/censor.rb +0 -97
  248. data/lib/more/facets/classmethods.rb +0 -199
  249. data/lib/more/facets/consoleutils.rb +0 -99
  250. data/lib/more/facets/crypt.rb +0 -166
  251. data/lib/more/facets/dependency.rb +0 -151
  252. data/lib/more/facets/downloader.rb +0 -281
  253. data/lib/more/facets/duplicable.rb +0 -43
  254. data/lib/more/facets/elementor.rb +0 -133
  255. data/lib/more/facets/filter.rb +0 -121
  256. data/lib/more/facets/heap.rb +0 -22
  257. data/lib/more/facets/infinity.rb +0 -193
  258. data/lib/more/facets/ini.rb +0 -264
  259. data/lib/more/facets/instantise.rb +0 -1
  260. data/lib/more/facets/instantize.rb +0 -95
  261. data/lib/more/facets/interval.rb +0 -282
  262. data/lib/more/facets/iteration.rb +0 -65
  263. data/lib/more/facets/linkedlist.rb +0 -222
  264. data/lib/more/facets/lrucache.rb +0 -157
  265. data/lib/more/facets/matcher.rb +0 -140
  266. data/lib/more/facets/memoizer.rb +0 -74
  267. data/lib/more/facets/minitar.rb +0 -1063
  268. data/lib/more/facets/nackclass.rb +0 -41
  269. data/lib/more/facets/net/smtp_tls.rb +0 -131
  270. data/lib/more/facets/nilstatus.rb +0 -48
  271. data/lib/more/facets/overload.rb +0 -94
  272. data/lib/more/facets/paramix.rb +0 -202
  273. data/lib/more/facets/pool.rb +0 -91
  274. data/lib/more/facets/pqueue.rb +0 -449
  275. data/lib/more/facets/pry.rb +0 -32
  276. data/lib/more/facets/reflection.rb +0 -145
  277. data/lib/more/facets/semaphore.rb +0 -92
  278. data/lib/more/facets/settings.rb +0 -248
  279. data/lib/more/facets/snapshot.rb +0 -209
  280. data/lib/more/facets/sparse_array.rb +0 -809
  281. data/lib/more/facets/string/mask.rb +0 -278
  282. data/lib/more/facets/string/obfuscate.rb +0 -65
  283. data/lib/more/facets/string/stylize.rb +0 -169
  284. data/lib/more/facets/string/words.rb +0 -167
  285. data/lib/more/facets/syncarray.rb +0 -114
  286. data/lib/more/facets/synchash.rb +0 -157
  287. data/lib/more/facets/typecast.rb +0 -261
  288. data/lib/more/facets/uninheritable.rb +0 -50
  289. data/lib/more/facets/xmlhash.rb +0 -112
  290. data/lib/more/facets/xoxo.rb +0 -259
  291. data/lib/more/facets/ziputils.rb +0 -490
  292. data/task/conflicts +0 -63
  293. data/task/coverage.rake +0 -37
  294. data/task/methods +0 -49
  295. data/task/rdoc.rake +0 -17
  296. data/task/setup.rake +0 -38
  297. data/task/test.rake +0 -145
  298. data/test/more/test_advisable.rb +0 -71
  299. data/test/more/test_association.rb +0 -38
  300. data/test/more/test_bbcode.rb +0 -21
  301. data/test/more/test_binreadable.rb +0 -50
  302. data/test/more/test_buildable.rb +0 -73
  303. data/test/more/test_classmethods.rb +0 -56
  304. data/test/more/test_crypt.rb +0 -32
  305. data/test/more/test_dependency.rb +0 -69
  306. data/test/more/test_elementwise.rb +0 -25
  307. data/test/more/test_infinity.rb +0 -40
  308. data/test/more/test_interval.rb +0 -151
  309. data/test/more/test_linkedlist.rb +0 -41
  310. data/test/more/test_lrucache.rb +0 -14
  311. data/test/more/test_overload.rb +0 -160
  312. data/test/more/test_paramix.rb +0 -170
  313. data/test/more/test_prototype.rb +0 -35
  314. data/test/more/test_snapshot.rb +0 -21
  315. data/test/more/test_sparsearray.rb +0 -279
  316. data/test/more/test_syncarray.rb +0 -15
  317. data/test/more/test_synchash.rb +0 -16
  318. data/test/more/test_typecast.rb +0 -54
  319. data/test/more/test_uninheritable.rb +0 -31
  320. data/test/more/test_xoxo.rb +0 -274
  321. data/test/test_facets.rb +0 -9
@@ -0,0 +1,24 @@
1
+ $FIRST_CLASS_INSTANCE_METHODS = Hash.new{ |h,k| h[k] = {} }
2
+
3
+ #
4
+ class Module
5
+
6
+ # Access method as a singleton object and retain state.
7
+ #
8
+ # module K
9
+ # def hello
10
+ # puts "Hello World!"
11
+ # end
12
+ # end
13
+ # p K.instance_method!(:hello) #=> <UnboundMethod: #hello>
14
+ #
15
+ # NOTE: This is limited to the scope of the current module/class.
16
+
17
+ def instance_method!(s)
18
+ #( @@__instance_methods__ ||= {} )[s] ||= instance_method(s) # TODO: use class vars for 1.9+ ?
19
+ #( @__instance_methods__ ||= {} )[s.to_sym] ||= instance_method(s.to_sym)
20
+ $FIRST_CLASS_INSTANCE_METHODS[self][s.to_sym] ||= instance_method(s.to_sym)
21
+ end
22
+
23
+ end
24
+
@@ -1,56 +1,72 @@
1
1
  class Module
2
2
 
3
- #unless (RUBY_VERSION[0,3] == '1.9')
3
+ # Load file directly into module/class namespace.
4
+ #
5
+ # Please use this with careful consideration.
6
+ # It is best suited to loading plugin-type scripts,
7
+ # and should generally not be used as a substitue for
8
+ # Ruby's standard load system.
9
+ #
10
+ # CREDIT: Trans
4
11
 
5
- # Load file into module/class namespace.
6
- #
7
- # CREDIT: Trans
8
-
9
- def module_load( path )
10
- if path =~ /^[\/~.]/
11
- file = File.expand_path(path)
12
- else
13
- $LOAD_PATH.each do |lp|
14
- file = File.join(lp,path)
15
- break if File.exist?(file)
16
- file = nil
17
- end
12
+ def module_load( path )
13
+ if path =~ /^[\/~.]/
14
+ file = File.expand_path(path)
15
+ else
16
+ $LOAD_PATH.each do |lp|
17
+ file = File.join(lp,path)
18
+ break if File.exist?(file)
19
+ file = nil
18
20
  end
19
- raise LoadError, "no such file to load -- #{path}" unless file
20
- module_eval(File.read(file))
21
21
  end
22
+ raise LoadError, "no such file to load -- #{path}" unless file
23
+ module_eval(File.read(file))
24
+ end
22
25
 
23
- # Require file into module/class namespace.
24
- #
25
- # CREDIT: Trans
26
+ # Require file into module/class namespace.
27
+ #
28
+ # Unlike load this keeps a per-module cache and will
29
+ # not load the same file into the same module more
30
+ # than once despite repeated attempts.
31
+ #
32
+ # The cache is kept in a global var called +$module_require+.
33
+ #
34
+ # Please use this with careful consideration.
35
+ # It is best suited to loading plugin-type scripts,
36
+ # and should generally not be used as a substitue for
37
+ # Ruby's standard load system.
38
+ #
39
+ # CREDIT: Trans
26
40
 
27
- def module_require( path )
28
- if path =~ /^[\/~.]/
29
- file = File.expand_path(path)
30
- else
31
- $LOAD_PATH.each do |lp|
32
- file = File.join(lp,path)
33
- break if File.exist?(file)
34
- file += '.rb'
35
- break if File.exist?(file)
36
- file = nil
37
- end
38
- end
39
- raise LoadError, "no such file to load -- #{path}" unless file
40
- @loaded ||= {}
41
- if @loaded.key?(file)
42
- false
43
- else
44
- @loaded[file] = true
45
- script = File.read(file)
46
- module_eval(script)
47
- true
41
+ def module_require( path )
42
+ if path =~ /^[\/~.]/
43
+ file = File.expand_path(path)
44
+ else
45
+ $LOAD_PATH.each do |lp|
46
+ file = File.join(lp,path)
47
+ break if File.exist?(file)
48
+ file += '.rb'
49
+ break if File.exist?(file)
50
+ file = nil
48
51
  end
49
52
  end
53
+ raise LoadError, "no such file to load -- #{path}" unless file
54
+ # per-module load cache
55
+ $module_require ||= {}
56
+ $module_require[self] ||= {}
57
+ loaded = $module_require[self]
58
+ if loaded.key?(file)
59
+ false
60
+ else
61
+ loaded[file] = true
62
+ script = File.read(file)
63
+ module_eval(script)
64
+ true
65
+ end
66
+ end
50
67
 
51
- alias_method :class_require, :module_require
52
- alias_method :class_load, :module_load
53
-
54
- #end
68
+ alias_method :class_require, :module_require
69
+ alias_method :class_load, :module_load
55
70
 
56
71
  end
72
+
@@ -0,0 +1 @@
1
+ require 'facets/module/module_load'
@@ -1,6 +1,6 @@
1
1
  class NilClass
2
2
 
3
- unless defined? to_f
3
+ unless method_defined?(:to_f)
4
4
 
5
5
  # Allows <tt>nil</tt> to respond to #to_f.
6
6
  # Always returns <tt>0</tt>.
@@ -0,0 +1,3 @@
1
+ class << ObjectSpace
2
+ alias_method :[], :_id2ref
3
+ end
@@ -8,18 +8,19 @@ class Proc
8
8
  if args.empty?
9
9
  idx = (0...arity).to_a
10
10
  else
11
- raise ArgumentError, "argument count is greater than arity (#{args.size} > #{arity})" if args.size > arity
11
+ raise ArgumentError, "argument count is greater than prok.arity (#{args.size} > #{arity})" if args.size > arity
12
12
  raise ArgumentError, "arguments must be unique indexes" if args.uniq != args
13
13
  raise ArgumentError, "arguments must be indexes" if args.any?{ |a| !Fixnum===a }
14
14
  idx = (0...arity).to_a
15
- idx = args + (idx - args)
15
+ idx = args + (idx - args)
16
16
  end
17
17
 
18
+ pro = self
18
19
  rec = ''
19
20
  idx.each do |i|
20
21
  rec << "proc { |a#{i}| "
21
22
  end
22
- rec << "self["
23
+ rec << "pro["
23
24
  rec << (0...arity).to_a.collect{|i| "a#{i}"}.join(',')
24
25
  rec << "]"
25
26
  rec << "}" * arity
@@ -1,12 +1,18 @@
1
- unless (RUBY_VERSION[0,3] == '1.9')
1
+ class String
2
2
 
3
- class String
3
+ unless method_defined?(:bytes) # 1.8.7+
4
4
 
5
5
  # Upacks string into bytes.
6
6
  #
7
+ # Note, this is not 100% compatible with 1.8.7+
8
+ # which returns an enumerator instead of an array.
7
9
  #
8
- def bytes
9
- self.unpack('C*')
10
+ def bytes(&blk)
11
+ if block_given?
12
+ self.unpack('C*').each(&blk)
13
+ else
14
+ self.unpack('C*')
15
+ end
10
16
  end
11
17
 
12
18
  end
@@ -2,7 +2,7 @@ class String
2
2
 
3
3
  # Converts a string to camelcase.
4
4
  #
5
- # By default camelcase leaves the first charcter of the string as given.
5
+ # By default camelcase leaves the first character of the string as given.
6
6
  # If +first_letter+ is set to +:lower+ or +false+, then +#camelcase+ will
7
7
  # produce lowerCamelCase. If it is set to +:upper+ or +true+ it will
8
8
  # produce UpperCamelCase.
@@ -11,10 +11,11 @@ class String
11
11
  # paths to namespaces.
12
12
  #
13
13
  # Examples
14
- # "camel_case".camelcase #=> "CamelCase"
15
- # "camel/case".camelcase #=> "Camel::Case"
16
- # "camel_case".camelcase(false) #=> "camelCase"
14
+ # "camel_case".camelcase #=> "camelCase"
15
+ # "camel/case".camelcase(true) #=> "Camel::Case"
16
+ # "Camel_case".camelcase(false) #=> "camelCase"
17
17
  #
18
+ # TODO: Is this the best approach? Should lowerCamelCase be default instead?
18
19
  def camelcase(first_letter=nil)
19
20
  case first_letter
20
21
  when :upper, true
@@ -42,7 +43,7 @@ class String
42
43
  str = dup
43
44
  str.gsub!(/\/(.?)/){ "::#{$1.upcase}" } # NOT SO SURE ABOUT THIS
44
45
  str.gsub!(/(?:_+|-+)([a-z])/){ $1.upcase }
45
- str.gsub!(/(\A|\s)([a-z])/){ $1 + $2.downcase }
46
+ str.gsub!(/(\A|\s)([A-Z])/){ $1 + $2.downcase }
46
47
  str
47
48
  end
48
49
 
@@ -1,6 +1,10 @@
1
1
  class String
2
2
 
3
- unless defined?(chars) or defined?(::ActiveSupport) # 1.9 & ActiveSupport
3
+ # Some other library is defining this method but it is
4
+ # returning an Enumerator, not an array. Therefore we're
5
+ # overriding it regardless of it's inclusion in 1.9.
6
+ #
7
+ unless defined?(::ActiveSupport) # 1.9 & ActiveSupport
4
8
 
5
9
  # Returns an array of characters.
6
10
  #
@@ -1,6 +1,6 @@
1
1
  class String
2
2
 
3
- unless defined? each_char # 1.9
3
+ unless method_defined?(:each_char) # 1.9
4
4
 
5
5
  require 'strscan'
6
6
 
@@ -4,7 +4,7 @@ class String
4
4
 
5
5
  # Iterate through each word of a string.
6
6
  #
7
- # "a string".each_word { |word, range| ... }
7
+ # "a string".each_word { |word| ... }
8
8
  #
9
9
  def each_word(&block)
10
10
  words.each(&block)
@@ -1,13 +1,20 @@
1
- unless (RUBY_VERSION[0,3] == '1.9')
1
+ class String
2
2
 
3
- class String
3
+ unless method_defined?(:lines) # 1.8.7+
4
4
 
5
5
  # Returns an array of characters.
6
6
  #
7
7
  # "abc\n123".lines #=> ["abc","123"]
8
8
  #
9
- def lines
10
- self.split(/\n/)
9
+ # Note, this is not 100% compatible with 1.8.7+
10
+ # which returns an enumerator instead of an array.
11
+ #
12
+ def lines(&blk)
13
+ if block_given?
14
+ self.split(/\n/).each(&blk)
15
+ else
16
+ self.split(/\n/)
17
+ end
11
18
  end
12
19
 
13
20
  end
@@ -1,6 +1,6 @@
1
- unless (RUBY_VERSION[0,3] == '1.9')
1
+ class String
2
2
 
3
- class String
3
+ unless method_defined?(:start_with?) # 1.8.7+
4
4
 
5
5
  # Does a string start with the given prefix.
6
6
  #
@@ -13,6 +13,10 @@ unless (RUBY_VERSION[0,3] == '1.9')
13
13
  self.index(prefix) == 0
14
14
  end
15
15
 
16
+ end
17
+
18
+ unless method_defined?(:end_with?) # 1.8.7+
19
+
16
20
  # Does a string end with the given suffix?
17
21
  #
18
22
  # "hello".ends_with?("lo") #=> true
@@ -26,5 +30,8 @@ unless (RUBY_VERSION[0,3] == '1.9')
26
30
 
27
31
  end
28
32
 
33
+ alias_method :starts_with?, :start_with?
34
+ alias_method :ends_with? , :ends_with?
35
+
29
36
  end
30
37
 
@@ -0,0 +1,27 @@
1
+ class String
2
+
3
+ # Unfold paragrpahs.
4
+ #
5
+ # FIXME: Sometimes adds one too many blank lines. TEST!!!
6
+ #
7
+ def unfold
8
+ blank = false
9
+ text = ''
10
+ split(/\n/).each do |line|
11
+ if /\S/ !~ line
12
+ text << "\n\n"
13
+ blank = true
14
+ else
15
+ if /^(\s+|[*])/ =~ line
16
+ text << (line.rstrip + "\n")
17
+ else
18
+ text << (line.rstrip + " ")
19
+ end
20
+ blank = false
21
+ end
22
+ end
23
+ text = text.gsub(/(\n){3,}/,"\n\n")
24
+ text.rstrip
25
+ end
26
+
27
+ end
@@ -1,6 +1,6 @@
1
- unless (RUBY_VERSION[0,3] == '1.9')
1
+ class Symbol
2
2
 
3
- class Symbol
3
+ unless method_defined?(:succ) # 1.9+ TODO: is this right?
4
4
 
5
5
  # Successor method for symobol. This simply converts
6
6
  # the symbol to a string uses String#succ and then
@@ -8,7 +8,7 @@ unless (RUBY_VERSION[0,3] == '1.9')
8
8
  #
9
9
  # :a.succ => :b
10
10
  #
11
- # TODO: Make this work more like a simple character dial?
11
+ # TODO: Make this work more like a simple character dial?
12
12
 
13
13
  def succ
14
14
  self.to_s.succ.intern
@@ -0,0 +1,20 @@
1
+ class Symbol
2
+
3
+ # Does the block throw the symbol?
4
+ #
5
+ def thrown?
6
+ catch(self) do
7
+ begin
8
+ yield
9
+ true
10
+ rescue ArgumentError => err # 1.9 exception
11
+ #msg += ", not #{err.message.split(/ /).last}"
12
+ false
13
+ rescue NameError => err # 1.8 exception
14
+ #msg += ", not #{err.name.inspect}"
15
+ false
16
+ end
17
+ end
18
+ end
19
+
20
+ end
@@ -1,6 +1,6 @@
1
- unless (RUBY_VERSION[0,3] == '1.9')
1
+ class Symbol
2
2
 
3
- class Symbol
3
+ unless method_defined?(:to_proc) # 1.8.7+
4
4
 
5
5
  # Turn a symbol into a proc calling the method to
6
6
  # which it refers.
@@ -35,3 +35,4 @@ unless (RUBY_VERSION[0,3] == '1.9')
35
35
  end
36
36
 
37
37
  end
38
+
@@ -1,6 +1,6 @@
1
1
  class Time
2
2
 
3
- unless defined? to_time #1.9
3
+ unless method_defined?(:to_time) # 1.9
4
4
 
5
5
  # To be able to keep Dates and Times interchangeable
6
6
  # on conversions.
@@ -1,5 +1,4 @@
1
- require 'enumerator' if RUBY_VERSION < "1.9"
2
-
1
+ require 'facets/enumerator'
3
2
  require 'facets/hash/dearray_values'
4
3
 
5
4
  class Array
@@ -267,112 +266,54 @@ class NilClass
267
266
  end
268
267
 
269
268
 
270
- if RUBY_VERSION < "1.9"
271
-
272
- class Enumerable::Enumerator
273
-
274
- # Convert an Enumerable::Enumerator object into a hash.
275
- # This is equivalent to Array#to_h.
276
- #
277
- # e1 = [[1,:a],[2,:b],[3,:c]].to_enum
278
- # e1.to_h #=> { 1=>:a, 2=>:b, 3=>:c }
279
- #
280
- # e2 = [1,2,3,4,5].to_enum
281
- # e2.to_h #=> {5=>nil, 1=>2, 3=>4}
282
- #
283
- # e3 = [1,2,1,3,1,5].to_enum
284
- # e3.to_h #=> {1=>5}
285
- #
286
- # CREDIT: Sandor Szücs
287
-
288
- def to_h(mode=nil)
289
- to_a.to_h(mode)
290
- end
291
-
292
- # This is equivalent to Array#to_h_auto.
293
- #
294
- def to_h_auto
295
- to_a.to_h_auto
296
- end
297
-
298
- # This is equivalent to Array#to_h_splat.
299
- #
300
- def to_h_splat
301
- to_a.to_h_splat
302
- end
269
+ class Enumerator
303
270
 
304
- # This is equivalent to Array#to_h_flat.
305
- #
306
- def to_h_flat
307
- to_a.to_h_flat
308
- end
309
-
310
- # This is equivalent to Array#to_h_assoc.
311
- #
312
- def to_h_assoc
313
- to_a.to_h_assoc
314
- end
315
-
316
- # This is equivalent to Array#to_h_multi.
317
- #
318
- def to_h_multi
319
- to_a.to_h_multi
320
- end
271
+ # Convert an Enumerator object into a hash.
272
+ # This is equivalent to Array#to_h.
273
+ #
274
+ # e1 = [[1,:a],[2,:b],[3,:c]].to_enum
275
+ # e1.to_h #=> { 1=>:a, 2=>:b, 3=>:c }
276
+ #
277
+ # e2 = [1,2,3,4,5].to_enum
278
+ # e2.to_h #=> {5=>nil, 1=>2, 3=>4}
279
+ #
280
+ # e3 = [1,2,1,3,1,5].to_enum
281
+ # e3.to_h #=> {1=>5}
282
+ #
283
+ # CREDIT: Sandor Szücs
321
284
 
285
+ def to_h(mode=nil)
286
+ to_a.to_h(mode)
322
287
  end
323
288
 
324
- else
325
-
326
- class Enumerator
327
-
328
- # Convert an Enumerator object into a hash.
329
- # This is equivalent to Array#to_h.
330
- #
331
- # e1 = [[1,:a],[2,:b],[3,:c]].to_enum
332
- # e1.to_h #=> { 1=>:a, 2=>:b, 3=>:c }
333
- #
334
- # e2 = [1,2,3,4,5].to_enum
335
- # e2.to_h #=> {5=>nil, 1=>2, 3=>4}
336
- #
337
- # e3 = [1,2,1,3,1,5].to_enum
338
- # e3.to_h #=> {1=>5}
339
- #
340
- # CREDIT: Sandor Szücs
341
-
342
- def to_h(mode=nil)
343
- to_a.to_h(mode)
344
- end
345
-
346
- # This is equivalent to Array#to_h_auto.
347
- #
348
- def to_h_auto
349
- to_a.to_h_auto
350
- end
351
-
352
- # This is equivalent to Array#to_h_splat.
353
- #
354
- def to_h_splat
355
- to_a.to_h_splat
356
- end
289
+ # This is equivalent to Array#to_h_auto.
290
+ #
291
+ def to_h_auto
292
+ to_a.to_h_auto
293
+ end
357
294
 
358
- # This is equivalent to Array#to_h_flat.
359
- #
360
- def to_h_flat
361
- to_a.to_h_flat
362
- end
295
+ # This is equivalent to Array#to_h_splat.
296
+ #
297
+ def to_h_splat
298
+ to_a.to_h_splat
299
+ end
363
300
 
364
- # This is equivalent to Array#to_h_assoc.
365
- #
366
- def to_h_assoc
367
- to_a.to_h_assoc
368
- end
301
+ # This is equivalent to Array#to_h_flat.
302
+ #
303
+ def to_h_flat
304
+ to_a.to_h_flat
305
+ end
369
306
 
370
- # This is equivalent to Array#to_h_multi.
371
- #
372
- def to_h_multi
373
- to_a.to_h_multi
374
- end
307
+ # This is equivalent to Array#to_h_assoc.
308
+ #
309
+ def to_h_assoc
310
+ to_a.to_h_assoc
311
+ end
375
312
 
313
+ # This is equivalent to Array#to_h_multi.
314
+ #
315
+ def to_h_multi
316
+ to_a.to_h_multi
376
317
  end
377
318
 
378
319
  end