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
@@ -20,7 +20,7 @@
20
20
  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21
21
  # FOR A PARTICULAR PURPOSE.
22
22
 
23
- require 'facets/class_extension'
23
+ require 'facets/class_extend'
24
24
 
25
25
  class Object
26
26
 
@@ -97,7 +97,7 @@ class Object
97
97
  (class << self; self; end).class_eval(&deflambda)
98
98
  elsif is_a?(Module)
99
99
  #class_inherit &deflambda
100
- extend class_extension(&deflambda)
100
+ extend class_extend(&deflambda)
101
101
  else # other Object
102
102
  (class << self; self; end).class_eval(&deflambda)
103
103
  end
@@ -0,0 +1,50 @@
1
+ require 'facets/functor'
2
+
3
+ class Object
4
+
5
+ # Access private internals of an object with a fluid notation.
6
+ #
7
+ # class X
8
+ # attr :a
9
+ # private :a
10
+ # def initialize
11
+ # @a = 1
12
+ # end
13
+ # end
14
+ #
15
+ # x = X.new
16
+ # p x.instance_eval.a #=> 1
17
+ # p x.a #=> Error
18
+ #
19
+ # A useful example might include adding accessors to a metaclass.
20
+ #
21
+ # class X
22
+ # metaclass.instance_eval.attr :x
23
+ # end
24
+ #
25
+ # This method is called #instance to go along with methods
26
+ # that provide similar access, such as #instance_variables
27
+ # and #instance_eval. In fact, one could argue this would be
28
+ # a good return value of #instance_eval is no block is given.
29
+ #
30
+ # This method was once called #pry and #privy.
31
+ #
32
+ # TODO: Will only support calls with blocks as of Ruby 1.9+.
33
+ #
34
+ def instance_eval(&block)
35
+ return super if block
36
+ @_instance_eval ||= Functor.new do |op, *a|
37
+ instance_eval{ send(op, *a) }
38
+ end
39
+ end
40
+
41
+ # TODO for Ruby 1.9
42
+ #def instance_eval(&block)
43
+ # return super if block
44
+ # @_instance_functor ||= Functor.new do |op, *a, &b|
45
+ # fcall(op, *a, &b)
46
+ # end
47
+ #end
48
+
49
+ end
50
+
@@ -0,0 +1,78 @@
1
+ class Module
2
+ # Converts module methods into instance methods such that the first parameter
3
+ # is passed +self+. This promotes DRY programming when wishing to offer both
4
+ # inheritable and module callable procedures.
5
+ #
6
+ # This method is modeled after +module_function+ which essentially has the the
7
+ # opposite effect. Due to implementation limitations, this must use the callback
8
+ # #singleton_method_added to emulate +module_function+ when no method names
9
+ # are given.
10
+ #
11
+ # module MyModule
12
+ # instance_function
13
+ #
14
+ # def self.jumble( obj, arg )
15
+ # obj + arg
16
+ # end
17
+ # end
18
+ #
19
+ # class String
20
+ # include MyModule
21
+ # end
22
+ #
23
+ # MyModule.jumble( "Try", "Me" ) #=> "TryMe"
24
+ #
25
+ # "Try".jumble( "Me" ) #=> 'TryMe'
26
+ #
27
+ # Note: This used to be a module called PromoteSelf and later Instantize,
28
+ # before becoming a method.
29
+ #
30
+ def instance_function(*meths)
31
+ if meths.empty?
32
+ extend InstanceFunction
33
+ else
34
+ meths.each do |meth|
35
+ class_eval %{
36
+ def #{meth}(*args)
37
+ #{self.name}.#{meth}(self,*args)
38
+ end
39
+ }
40
+ end
41
+ end
42
+ end
43
+
44
+ module InstanceFunction #:nodoc
45
+ #
46
+ def singleton_method_added(meth)
47
+ module_eval %{
48
+ def #{meth}(*args)
49
+ #{self.name}.#{meth}(self,*args)
50
+ end
51
+ }
52
+ #self.class_eval d
53
+ super(meth)
54
+ end
55
+ end
56
+
57
+ end #class Module
58
+
59
+ =begin
60
+ module Instantize
61
+
62
+ def self.append_features(mod)
63
+ mod.extend self
64
+ end
65
+
66
+ def singleton_method_added( meth )
67
+ d = %{
68
+ def #{meth}(*args)
69
+ #{self.name}.#{meth}(self,*args)
70
+ end
71
+ }
72
+ self.class_eval d
73
+ super(meth)
74
+ end
75
+
76
+ end
77
+ =end
78
+
@@ -1,30 +1,35 @@
1
- # = Main as Module
1
+ # Main as Module
2
+ # Copyright (c) 2006 Thomas Sawyer
3
+ # Ruby License
4
+ #
5
+ # This module is free software. You may use, modify, and/or redistribute this
6
+ # software under the same terms as Ruby.
7
+ #
8
+ # This program is distributed in the hope that it will be useful, but WITHOUT
9
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10
+ # FOR A PARTICULAR PURPOSE.
11
+ #
12
+ # == Description
2
13
  #
3
14
  # Main, ie. the top-level object, is not fully in-sync with
4
15
  # Module. So, certain methods like #define_method do not work.
5
16
  # This library fixes this.
6
17
  #
7
18
  # Techinally it is this authors opinion that the top-level object
8
- # most likely be better-off as a self-extended module, and
9
- # method defined in it do not automatically get added to the
19
+ # most likely would be better-off as a self-extended module, and
20
+ # methods defined in it do not automatically get added to the
10
21
  # Object class.
11
22
  #
12
- # == Copying
23
+ # On the other hand. It is probably best to never use the toplevel
24
+ # except as a jumping in point to youre own namespace.
13
25
  #
14
- # Copyright (c) 2006 Thomas Sawyer
15
- #
16
- # Ruby License
26
+ # == Note
17
27
  #
18
- # This module is free software. You may use, modify, and/or redistribute this
19
- # software under the same terms as Ruby.
20
- #
21
- # This program is distributed in the hope that it will be useful, but WITHOUT
22
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23
- # FOR A PARTICULAR PURPOSE.
28
+ # Noen of this would be needed if Main were just a self extended module.
24
29
  #
25
- # == Authors
30
+ # == Authors
26
31
  #
27
- # * Thomas Sawyer
32
+ # * Thomas Sawyer
28
33
 
29
34
  public
30
35
 
@@ -1,113 +1 @@
1
- # = Memoize
2
- #
3
- # Directive for making your functions faster by trading
4
- # space for time. When you "memoize" a method/function
5
- # its results are cached so that later calls with the
6
- # same arguments returns results in the cache instead
7
- # of recalculating them.
8
- #
9
- # class T
10
- # def initialize(a)
11
- # @a = a
12
- # end
13
- # def a
14
- # "#{@a ^ 3 + 4}"
15
- # end
16
- # memoize :a
17
- # end
18
- #
19
- # t = T.new(1)
20
- # t.a.__id__ == t.a.__id__ #=> true
21
- #
22
- # == Authors
23
- #
24
- # * trans
25
- # * rtb
26
- #
27
- # == Copying
28
- #
29
- # Copyright (c) 2005 Robert Feldt
30
- #
31
- # Ruby License
32
- #
33
- # This module is free software. You may use, modify, and/or redistribute this
34
- # software under the same terms as Ruby.
35
- #
36
- # This program is distributed in the hope that it will be useful, but WITHOUT
37
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
38
- # FOR A PARTICULAR PURPOSE.
39
-
40
- #require 'facets/memoizer'
41
-
42
- #
43
- class Module
44
-
45
- # Directive for making your functions faster by trading
46
- # space for time. When you "memoize" a method/function
47
- # its results are cached so that later calls with the
48
- # same arguments returns results in the cache instead
49
- # of recalculating them.
50
- #
51
- # class T
52
- # def initialize(a)
53
- # @a = a
54
- # end
55
- # def a
56
- # "#{@a ^ 3 + 4}"
57
- # end
58
- # memoize :a
59
- # end
60
- #
61
- # t = T.new
62
- # t.a.__id__ == t.a.__id__ #=> true
63
- #
64
- def memoize(*meths)
65
- meths.each do |meth|
66
- old = instance_method(meth)
67
- new = proc do |*args|
68
- mc = ((@_MEMOIZE_CACHE ||= {})[meth] ||= {})
69
- if mc.has_key? args
70
- mc[args]
71
- else
72
- mc[args] = old.bind(self).call(*args)
73
- end
74
- end
75
- send(:define_method, meth, &new)
76
- end
77
- end
78
-
79
- end
80
-
81
- # This allows memoize to work in main and instance scope too.
82
- def memoize(*args)
83
- Object.memoize(*args)
84
- end
85
-
86
- module Kernel #:nodoc:
87
-
88
- # Object#cache is essentially like Module#memoize except
89
- # it can also be used on singleton/eigen methods.
90
- # OTOH, memoize's implementation is arguably better for it's
91
- # use of #bind instead of #alias. Eventually the two implmenations
92
- # should be reconciled with a single implementation.
93
- #
94
- def cache m = nil
95
- if m
96
- (Module === self ? self : (class << self; self; end)).module_eval <<-code
97
- alias_method '__#{ m }__', '#{ m }'
98
- def #{ m }(*__a__,&__b__)
99
- c = cache['#{ m }']
100
- k = [__a__,__b__]
101
- if c.has_key? k
102
- c[k]
103
- else
104
- c[k] = __#{ m }__(*__a__,&__b__)
105
- end
106
- end
107
- code
108
- end
109
- @cache ||= Hash::new{|h,k| h[k]={}}
110
- end
111
-
112
- end
113
-
1
+ require 'facets/once'
@@ -0,0 +1,83 @@
1
+ class Module
2
+
3
+ # Create a toggle attribute. This creates two methods for
4
+ # each given name. One is a form of tester and the other
5
+ # is used to toggle the value.
6
+ #
7
+ # attr_accessor! :a
8
+ #
9
+ # is equivalent to
10
+ #
11
+ # def a?
12
+ # @a
13
+ # end
14
+ #
15
+ # def a!(value=true)
16
+ # @a = value
17
+ # self
18
+ # end
19
+ #
20
+ # CREDIT: Trans
21
+
22
+ def attr_switch_accessor(*args)
23
+ attr_reader!(*args) + attr_writer!(*args)
24
+ end
25
+
26
+ alias_method :attr_toggler, :attr_accessor!
27
+
28
+ # Create aliases for flag accessors.
29
+ #
30
+ # CREDIT: Trans
31
+
32
+ def alias_accessor!(*args)
33
+ orig = args.last
34
+ args = args - [orig]
35
+ args.each do |name|
36
+ alias_method("#{name}?", "#{orig}?")
37
+ alias_method("#{name}!", "#{orig}!")
38
+ end
39
+ end
40
+ alias_method :alias_switcher, :alias_accessor!
41
+ alias_method :alias_toggler, :alias_accessor!
42
+
43
+ # Create a flaggable attribute. This creates a single methods
44
+ # used to set an attribute to "true".
45
+ #
46
+ # attr_writer! :a
47
+ #
48
+ # is equivalent to
49
+ #
50
+ # def a!(value=true)
51
+ # @a = value
52
+ # self
53
+ # end
54
+ #
55
+ def attr_writer!(*args)
56
+ code, made = '', []
57
+ args.each do |a|
58
+ code << %{
59
+ def #{a}!(value=true)
60
+ @#{a} = value
61
+ self
62
+ end
63
+ }
64
+ made << "#{a}!".to_sym
65
+ end
66
+ module_eval code
67
+ made
68
+ end
69
+
70
+ # Create aliases for flag writer.
71
+ #
72
+ # CREDIT: Trans
73
+
74
+ def alias_writer!(*args)
75
+ orig = args.last
76
+ args = args - [orig]
77
+ args.each do |name|
78
+ alias_method("#{name}!", "#{orig}!")
79
+ end
80
+ end
81
+
82
+ end
83
+
@@ -0,0 +1,44 @@
1
+ class Module
2
+
3
+ # Create an tester attribute. This creates a single method
4
+ # used to test the attribute for truth.
5
+ #
6
+ # attr_tester :a
7
+ #
8
+ # is equivalent to
9
+ #
10
+ # def a?
11
+ # @a ? true : @a
12
+ # end
13
+ #
14
+ def attr_tester(*args)
15
+ code, made = '', []
16
+ args.each do |a|
17
+ code << %{
18
+ def #{a}?(truth=nil)
19
+ @#{a} ? truth || @#{a} : @#{a}
20
+ end
21
+ }
22
+ made << "#{a}?".to_sym
23
+ end
24
+ module_eval code
25
+ made
26
+ end
27
+
28
+ alias_method :attr_reader?, :attr_tester
29
+
30
+ # Create aliases for flag reader.
31
+ #
32
+ # CREDIT: Trans
33
+
34
+ def alias_tester(*args)
35
+ orig = args.last
36
+ args = args - [orig]
37
+ args.each do |name|
38
+ alias_method("#{name}?", "#{orig}?")
39
+ end
40
+ end
41
+ alias_method :alias_reader?, :alias_tester
42
+
43
+ end
44
+
@@ -0,0 +1,59 @@
1
+ require 'facets/attr_tester'
2
+
3
+ class Module
4
+
5
+ # Create a flaggable attribute. This creates a single methods
6
+ # used to set an attribute to "true".
7
+ #
8
+ # attr_toggler :a
9
+ #
10
+ # is equivalent to
11
+ #
12
+ # def a?
13
+ # @a ? true : @a
14
+ # end
15
+ #
16
+ # def a!(value=Exception)
17
+ # if Exception
18
+ # @a = @a ? false : true
19
+ # else
20
+ # @a = value
21
+ # end
22
+ # self
23
+ # end
24
+ #
25
+ def attr_toggler(*args)
26
+ code, made = '', []
27
+ args.each do |a|
28
+ code << %{
29
+ def #{a}!(value=Excception)
30
+ if Exception
31
+ @a = @a ? false : true
32
+ else
33
+ @a = value
34
+ end
35
+ self
36
+ end
37
+ }
38
+ made << "#{a}!".to_sym
39
+ end
40
+ module_eval code
41
+ made.concat(attr_tester(*args))
42
+ made
43
+ end
44
+
45
+ # Create aliases for attr_toggler.
46
+ #
47
+ # CREDIT: Trans
48
+
49
+ def alias_toggler(*args)
50
+ orig = args.last
51
+ args = args - [orig]
52
+ args.each do |name|
53
+ alias_method("#{name}!", "#{orig}!")
54
+ alias_method("#{name}?", "#{orig}?")
55
+ end
56
+ end
57
+
58
+ end
59
+