facets 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.rdoc +331 -35
- data/MANIFEST +685 -826
- data/{doc/guide/notes.rd → NOTES} +0 -0
- data/README.rdoc +73 -25
- data/Rakefile +245 -2
- data/TODO +5 -0
- data/demo/hook.rd +47 -0
- data/demo/scenario_require.rd +9 -0
- data/doc/README.more +24 -6
- data/doc/manual/about.rb +47 -0
- data/doc/manual/annotations.rdoc +60 -0
- data/doc/manual/associations.rdoc +55 -0
- data/doc/manual/blockups.rdoc +101 -0
- data/doc/manual/capsule.rdoc +34 -0
- data/doc/manual/command.rdoc +177 -0
- data/doc/manual/core.rdoc +37 -0
- data/doc/manual/faq.rdoc +32 -0
- data/doc/manual/typecast.html +112 -0
- data/lib/core/facets.rb +359 -11
- data/lib/core/facets/array/combination.rb +3 -3
- data/lib/core/facets/array/index.rb +4 -1
- data/lib/core/facets/array/permutation.rb +2 -2
- data/lib/core/facets/array/product.rb +1 -1
- data/lib/core/facets/binding/eval.rb +1 -1
- data/lib/core/facets/denumerable.rb +76 -0
- data/lib/core/facets/duplicable.rb +34 -0
- data/lib/core/facets/enumerable/count.rb +10 -4
- data/lib/core/facets/enumerable/defer.rb +77 -0
- data/lib/core/facets/enumerable/each_by.rb +1 -1
- data/lib/core/facets/enumerable/every.rb +35 -0
- data/lib/{more/facets/elementwise.rb → core/facets/enumerable/ewise.rb} +0 -0
- data/lib/core/facets/enumerable/filter.rb +25 -0
- data/lib/core/facets/enumerable/group_by.rb +1 -1
- data/lib/core/facets/enumerable/none.rb +3 -2
- data/lib/core/facets/enumerable/one.rb +3 -2
- data/lib/core/facets/enumerable/per.rb +61 -0
- data/lib/core/facets/exception/raised.rb +14 -0
- data/lib/core/facets/integer/odd.rb +5 -1
- data/lib/core/facets/kernel/__dir__.rb +13 -3
- data/lib/core/facets/kernel/__here__.rb +14 -0
- data/lib/core/facets/kernel/__method__.rb +9 -3
- data/lib/core/facets/kernel/ask.rb +1 -0
- data/lib/core/facets/kernel/equate.rb +13 -0
- data/lib/core/facets/kernel/extension.rb +9 -0
- data/lib/core/facets/kernel/identical.rb +4 -0
- data/lib/core/facets/kernel/instance_exec.rb +2 -1
- data/lib/core/facets/kernel/method.rb +49 -0
- data/lib/core/facets/kernel/object_send.rb +2 -2
- data/lib/core/facets/kernel/{state.rb → object_state.rb} +23 -12
- data/lib/core/facets/kernel/require_all.rb +6 -1
- data/lib/core/facets/kernel/require_local.rb +8 -1
- data/lib/core/facets/kernel/require_relative.rb +52 -0
- data/lib/core/facets/kernel/source_location.rb +13 -0
- data/lib/core/facets/kernel/tap.rb +13 -6
- data/lib/core/facets/module/attr_setter.rb +57 -0
- data/lib/core/facets/module/instance_method.rb +24 -0
- data/lib/core/facets/module/module_load.rb +60 -44
- data/lib/core/facets/module/module_require.rb +1 -0
- data/lib/core/facets/nilclass/to_f.rb +1 -1
- data/lib/core/facets/objectspace/op_fetch.rb +3 -0
- data/lib/core/facets/proc/curry.rb +4 -3
- data/lib/core/facets/string/bytes.rb +10 -4
- data/lib/core/facets/string/camelcase.rb +6 -5
- data/lib/core/facets/string/chars.rb +5 -1
- data/lib/core/facets/string/each_char.rb +1 -1
- data/lib/core/facets/string/each_word.rb +1 -1
- data/lib/core/facets/string/lines.rb +11 -4
- data/lib/core/facets/string/start_with.rb +9 -2
- data/lib/core/facets/string/unfold.rb +27 -0
- data/lib/core/facets/symbol/succ.rb +3 -3
- data/lib/core/facets/symbol/thrown.rb +20 -0
- data/lib/core/facets/symbol/to_proc.rb +3 -2
- data/lib/core/facets/time/to_time.rb +1 -1
- data/lib/core/facets/to_hash.rb +41 -100
- data/lib/core/facets/unboundmethod/name.rb +20 -23
- data/lib/more/facets/ansicode.rb +1 -10
- data/lib/more/facets/autoarray.rb +3 -31
- data/lib/more/facets/basicobject.rb +73 -0
- data/lib/more/facets/blankslate.rb +2 -66
- data/lib/{lore → more}/facets/cgi.rb +0 -0
- data/lib/more/facets/class_extend.rb +1 -0
- data/lib/{lore → more}/facets/continuation.rb +0 -0
- data/lib/{lore → more}/facets/date.rb +3 -3
- data/lib/more/facets/enumargs.rb +192 -0
- data/lib/more/facets/enumerablepass.rb +2 -216
- data/lib/more/facets/enumerator.rb +62 -0
- data/lib/more/facets/{equatable.rb → equitable.rb} +11 -11
- data/lib/more/facets/expirable.rb +13 -41
- data/lib/{lore → more}/facets/fileutils.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/head.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/safe_ln.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/slice.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/tail.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/wc.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/whereis.rb +0 -0
- data/lib/{lore → more}/facets/fileutils/which.rb +0 -0
- data/lib/{lore → more}/facets/getoptlong.rb +0 -0
- data/lib/more/facets/hook.rb +2 -29
- data/lib/more/facets/inheritor.rb +2 -2
- data/lib/more/facets/instance_eval.rb +50 -0
- data/lib/more/facets/instance_function.rb +78 -0
- data/lib/more/facets/main.rb +20 -15
- data/lib/more/facets/memoize.rb +1 -113
- data/lib/more/facets/module/attr.rb +83 -0
- data/lib/more/facets/module/attr_tester.rb +44 -0
- data/lib/more/facets/module/attr_toggler.rb +59 -0
- data/lib/more/facets/module/attr_validator.rb +34 -0
- data/lib/more/facets/{class_extension.rb → module/class_extend.rb} +21 -13
- data/lib/more/facets/once.rb +59 -0
- data/lib/more/facets/openmodule.rb +1 -0
- data/lib/more/facets/orderedhash.rb +1 -33
- data/lib/{lore → more}/facets/ostruct.rb +0 -0
- data/lib/more/facets/ostructable.rb +1 -4
- data/lib/more/facets/partial.rb +18 -16
- data/lib/{lore → more}/facets/pathname.rb +0 -0
- data/lib/more/facets/preinitialize.rb +157 -0
- data/lib/{lore → more}/facets/rbconfig.rb +0 -0
- data/lib/more/facets/recorder.rb +1 -2
- data/lib/{lore → more}/facets/set.rb +0 -0
- data/lib/{lore → more}/facets/shellwords.rb +0 -0
- data/lib/{lore → more}/facets/uri.rb +0 -0
- data/lib/{lore → more}/facets/yaml.rb +0 -0
- data/lib/{lore → more}/facets/zlib.rb +0 -0
- data/meta/loadpath +0 -1
- data/meta/sitemap +4 -0
- data/meta/version +1 -1
- data/test/core/enumerable/test_count.rb +1 -1
- data/test/{more/test_filter.rb → core/enumerable/test_defer.rb} +24 -22
- data/test/{more/test_elementor.rb → core/enumerable/test_every.rb} +2 -15
- data/test/core/enumerable/test_ewise.rb +23 -0
- data/test/core/enumerable/test_per.rb +18 -0
- data/test/core/enumerable/test_take.rb +13 -0
- data/test/core/kernel/test_deepcopy.rb +1 -1
- data/test/{more/test_1stclassmethod.rb → core/kernel/test_method.rb} +2 -7
- data/test/core/kernel/test_tap.rb +1 -1
- data/test/core/proc/test_curry.rb +11 -0
- data/test/core/string/test_bytes.rb +1 -1
- data/test/core/string/test_camelcase.rb +23 -6
- data/test/core/string/test_lines.rb +1 -1
- data/test/core/string/test_unfold.rb +14 -0
- data/test/{more → core}/test_blank.rb +0 -0
- data/test/{more → core}/test_boolean.rb +0 -0
- data/test/{more → core}/test_functor.rb +0 -0
- data/test/{lore → more}/test_basicobject.rb +0 -0
- data/test/more/{test_class_extension.rb → test_class_extend.rb} +6 -6
- data/test/{lore → more}/test_continuation.rb +0 -0
- data/test/{lore → more}/test_date.rb +0 -0
- data/test/more/{test_enumerablepass.rb → test_enumargs.rb} +2 -4
- data/test/more/{test_equatable.rb → test_equitable.rb} +2 -2
- data/test/more/{test_instantise.rb → test_instance_function.rb} +3 -2
- data/test/more/test_memoize.rb +1 -1
- data/test/{lore → more}/test_ostruct.rb +0 -0
- metadata +865 -1016
- data/RELEASE +0 -38
- data/doc/README.lore +0 -51
- data/doc/log/basic_stats/index.html +0 -39
- data/doc/log/changelog.html +0 -648
- data/doc/log/changelog.txt +0 -217
- data/doc/log/stats/index.html +0 -39
- data/doc/log/testlog.txt +0 -278
- data/doc/notes/CHANGES +0 -2529
- data/doc/rdoc/lore/classes/Array.html +0 -176
- data/doc/rdoc/lore/classes/CGI.html +0 -191
- data/doc/rdoc/lore/classes/Config.html +0 -135
- data/doc/rdoc/lore/classes/Continuation.html +0 -113
- data/doc/rdoc/lore/classes/Date.html +0 -631
- data/doc/rdoc/lore/classes/DateTime.html +0 -583
- data/doc/rdoc/lore/classes/Enumerable.html +0 -89
- data/doc/rdoc/lore/classes/Enumerable/Enumerator.html +0 -147
- data/doc/rdoc/lore/classes/File.html +0 -128
- data/doc/rdoc/lore/classes/FileUtils.html +0 -434
- data/doc/rdoc/lore/classes/GetoptLong.html +0 -118
- data/doc/rdoc/lore/classes/GetoptLong/DSL.html +0 -208
- data/doc/rdoc/lore/classes/Kernel.html +0 -135
- data/doc/rdoc/lore/classes/Logger.html +0 -229
- data/doc/rdoc/lore/classes/Logger/Ansicolor.html +0 -277
- data/doc/rdoc/lore/classes/Logger/LogDevice.html +0 -121
- data/doc/rdoc/lore/classes/NilClass.html +0 -119
- data/doc/rdoc/lore/classes/OpenStruct.html +0 -432
- data/doc/rdoc/lore/classes/Pathname.html +0 -353
- data/doc/rdoc/lore/classes/Set.html +0 -117
- data/doc/rdoc/lore/classes/Shellwords.html +0 -111
- data/doc/rdoc/lore/classes/String.html +0 -140
- data/doc/rdoc/lore/classes/Time.html +0 -154
- data/doc/rdoc/lore/classes/URI.html +0 -454
- data/doc/rdoc/lore/classes/URI/Hash.html +0 -105
- data/doc/rdoc/lore/classes/URI/Kernel.html +0 -122
- data/doc/rdoc/lore/classes/Zlib.html +0 -188
- data/doc/rdoc/lore/created.rid +0 -1
- data/doc/rdoc/lore/files/README.html +0 -286
- data/doc/rdoc/lore/files/doc/README_lore.html +0 -155
- data/doc/rdoc/lore/files/lib/lore/facets/basicobject_rb.html +0 -118
- data/doc/rdoc/lore/files/lib/lore/facets/cgi_rb.html +0 -111
- data/doc/rdoc/lore/files/lib/lore/facets/continuation_rb.html +0 -147
- data/doc/rdoc/lore/files/lib/lore/facets/date_rb.html +0 -97
- data/doc/rdoc/lore/files/lib/lore/facets/enumerator_rb.html +0 -111
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/head_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/safe_ln_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/slice_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/tail_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/wc_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/whereis_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils/which_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/fileutils_rb.html +0 -131
- data/doc/rdoc/lore/files/lib/lore/facets/getoptlong_rb.html +0 -135
- data/doc/rdoc/lore/files/lib/lore/facets/logger_rb.html +0 -142
- data/doc/rdoc/lore/files/lib/lore/facets/ostruct_rb.html +0 -135
- data/doc/rdoc/lore/files/lib/lore/facets/pathname_rb.html +0 -145
- data/doc/rdoc/lore/files/lib/lore/facets/rbconfig_rb.html +0 -124
- data/doc/rdoc/lore/files/lib/lore/facets/set_rb.html +0 -96
- data/doc/rdoc/lore/files/lib/lore/facets/shellwords_rb.html +0 -124
- data/doc/rdoc/lore/files/lib/lore/facets/uri_rb.html +0 -125
- data/doc/rdoc/lore/files/lib/lore/facets/yaml_rb.html +0 -146
- data/doc/rdoc/lore/files/lib/lore/facets/zlib_rb.html +0 -97
- data/doc/rdoc/lore/fr_class_index.html +0 -73
- data/doc/rdoc/lore/fr_file_index.html +0 -71
- data/doc/rdoc/lore/fr_method_index.html +0 -177
- data/doc/rdoc/lore/index.html +0 -26
- data/doc/rdoc/lore/rdoc-style.css +0 -177
- data/doc/release-notes/RELEASE-2.0.5 +0 -8
- data/doc/release-notes/RELEASE-2.1.0 +0 -9
- data/doc/release-notes/RELEASE-2.1.1 +0 -5
- data/doc/release-notes/RELEASE-2.1.2 +0 -6
- data/doc/release-notes/RELEASE-2.1.3 +0 -5
- data/doc/release-notes/RELEASE-2.2.0 +0 -14
- data/doc/release-notes/RELEASE-2.2.1 +0 -4
- data/doc/release-notes/RELEASE-2.3.0 +0 -6
- data/doc/release-notes/RELEASE-2.4.0 +0 -70
- data/doc/release-notes/RELEASE-2.4.1 +0 -8
- data/doc/release-notes/RELEASE-2.4.2 +0 -4
- data/doc/release-notes/RELEASE-2.4.3 +0 -78
- data/doc/release-notes/RELEASE-2.4.4 +0 -38
- data/doc/release-notes/RELEASE-2.4.5 +0 -37
- data/doc/release-notes/RELEASE-2.5.0 +0 -83
- data/lib/core/facets/kernel/instance.rb +0 -19
- data/lib/lore/facets/basicobject.rb +0 -14
- data/lib/lore/facets/enumerator.rb +0 -67
- data/lib/lore/facets/logger.rb +0 -291
- data/lib/more/facets/1stclassmethod.rb +0 -140
- data/lib/more/facets/advisable.rb +0 -162
- data/lib/more/facets/association.rb +0 -210
- data/lib/more/facets/attr.rb +0 -209
- data/lib/more/facets/basex.rb +0 -37
- data/lib/more/facets/bbcode.rb +0 -397
- data/lib/more/facets/bicrypt.rb +0 -265
- data/lib/more/facets/binreadable.rb +0 -221
- data/lib/more/facets/censor.rb +0 -97
- data/lib/more/facets/classmethods.rb +0 -199
- data/lib/more/facets/consoleutils.rb +0 -99
- data/lib/more/facets/crypt.rb +0 -166
- data/lib/more/facets/dependency.rb +0 -151
- data/lib/more/facets/downloader.rb +0 -281
- data/lib/more/facets/duplicable.rb +0 -43
- data/lib/more/facets/elementor.rb +0 -133
- data/lib/more/facets/filter.rb +0 -121
- data/lib/more/facets/heap.rb +0 -22
- data/lib/more/facets/infinity.rb +0 -193
- data/lib/more/facets/ini.rb +0 -264
- data/lib/more/facets/instantise.rb +0 -1
- data/lib/more/facets/instantize.rb +0 -95
- data/lib/more/facets/interval.rb +0 -282
- data/lib/more/facets/iteration.rb +0 -65
- data/lib/more/facets/linkedlist.rb +0 -222
- data/lib/more/facets/lrucache.rb +0 -157
- data/lib/more/facets/matcher.rb +0 -140
- data/lib/more/facets/memoizer.rb +0 -74
- data/lib/more/facets/minitar.rb +0 -1063
- data/lib/more/facets/nackclass.rb +0 -41
- data/lib/more/facets/net/smtp_tls.rb +0 -131
- data/lib/more/facets/nilstatus.rb +0 -48
- data/lib/more/facets/overload.rb +0 -94
- data/lib/more/facets/paramix.rb +0 -202
- data/lib/more/facets/pool.rb +0 -91
- data/lib/more/facets/pqueue.rb +0 -449
- data/lib/more/facets/pry.rb +0 -32
- data/lib/more/facets/reflection.rb +0 -145
- data/lib/more/facets/semaphore.rb +0 -92
- data/lib/more/facets/settings.rb +0 -248
- data/lib/more/facets/snapshot.rb +0 -209
- data/lib/more/facets/sparse_array.rb +0 -809
- data/lib/more/facets/string/mask.rb +0 -278
- data/lib/more/facets/string/obfuscate.rb +0 -65
- data/lib/more/facets/string/stylize.rb +0 -169
- data/lib/more/facets/string/words.rb +0 -167
- data/lib/more/facets/syncarray.rb +0 -114
- data/lib/more/facets/synchash.rb +0 -157
- data/lib/more/facets/typecast.rb +0 -261
- data/lib/more/facets/uninheritable.rb +0 -50
- data/lib/more/facets/xmlhash.rb +0 -112
- data/lib/more/facets/xoxo.rb +0 -259
- data/lib/more/facets/ziputils.rb +0 -490
- data/task/conflicts +0 -63
- data/task/coverage.rake +0 -37
- data/task/methods +0 -49
- data/task/rdoc.rake +0 -17
- data/task/setup.rake +0 -38
- data/task/test.rake +0 -145
- data/test/more/test_advisable.rb +0 -71
- data/test/more/test_association.rb +0 -38
- data/test/more/test_bbcode.rb +0 -21
- data/test/more/test_binreadable.rb +0 -50
- data/test/more/test_buildable.rb +0 -73
- data/test/more/test_classmethods.rb +0 -56
- data/test/more/test_crypt.rb +0 -32
- data/test/more/test_dependency.rb +0 -69
- data/test/more/test_elementwise.rb +0 -25
- data/test/more/test_infinity.rb +0 -40
- data/test/more/test_interval.rb +0 -151
- data/test/more/test_linkedlist.rb +0 -41
- data/test/more/test_lrucache.rb +0 -14
- data/test/more/test_overload.rb +0 -160
- data/test/more/test_paramix.rb +0 -170
- data/test/more/test_prototype.rb +0 -35
- data/test/more/test_snapshot.rb +0 -21
- data/test/more/test_sparsearray.rb +0 -279
- data/test/more/test_syncarray.rb +0 -15
- data/test/more/test_synchash.rb +0 -16
- data/test/more/test_typecast.rb +0 -54
- data/test/more/test_uninheritable.rb +0 -31
- data/test/more/test_xoxo.rb +0 -274
- data/test/test_facets.rb +0 -9
@@ -1,140 +0,0 @@
|
|
1
|
-
# = First Class Methods
|
2
|
-
#
|
3
|
-
# Gives Ruby 1st class methods.
|
4
|
-
#
|
5
|
-
# Easy access to method as objects, and they retain state!
|
6
|
-
#
|
7
|
-
# def hello
|
8
|
-
# puts "Hello World!"
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# m1 = method!(:hello) #=> <Method: #hello>
|
12
|
-
#
|
13
|
-
# def m1.annotate
|
14
|
-
# "simple example"
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# m2 = method!(:hello)
|
18
|
-
# m2.annotate #=> "simple example"
|
19
|
-
#
|
20
|
-
# Easy access to method as objects, and they retain state!
|
21
|
-
#
|
22
|
-
# module K
|
23
|
-
# def hello
|
24
|
-
# puts "Hello World!"
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
# p K.instance_method!(:hello) #=> <UnboundMethod: #hello>
|
28
|
-
#
|
29
|
-
# CAUTION! This it is currently limited to the scope of the
|
30
|
-
# current module/class.
|
31
|
-
#
|
32
|
-
# == Notes
|
33
|
-
#
|
34
|
-
# Should 1st Class Methods be part of Ruby proper?
|
35
|
-
#
|
36
|
-
# Perhaps the best solution would be using the notation
|
37
|
-
# <tt>::ameth</tt>. This would require some minor changes
|
38
|
-
# to Ruby, but with few backward incompatabilites if
|
39
|
-
# parantheticals revert back to the actual method invocation.
|
40
|
-
# Although this later stipulation means capitalized methods
|
41
|
-
# would not be accessible in this way b/c they would intefere with
|
42
|
-
# constant lookup. It's a trade off.
|
43
|
-
#
|
44
|
-
# Current Proposed Alternate
|
45
|
-
# ----------------- ------------------ -------------------
|
46
|
-
# Foo.Bar() method call method call method call
|
47
|
-
# Foo.Bar method call method call method call
|
48
|
-
# Foo.bar() method call method call method call
|
49
|
-
# Foo.bar method call method call method call
|
50
|
-
# Foo::Bar() method call method call 1st class method
|
51
|
-
# Foo::Bar constant lookup constant lookup constant lookup
|
52
|
-
# Foo::bar() method call method call 1st class method
|
53
|
-
# Foo::bar method call 1st class method 1st class method
|
54
|
-
#
|
55
|
-
# Then again this dosen't address bound versus unbound.
|
56
|
-
#
|
57
|
-
# Which do you prefer?
|
58
|
-
#
|
59
|
-
# == Authors
|
60
|
-
#
|
61
|
-
# * Thomas Sawyer
|
62
|
-
#
|
63
|
-
# == Copying
|
64
|
-
#
|
65
|
-
# Copyright (c) 2005 Thomas Sawyer
|
66
|
-
#
|
67
|
-
# Ruby License
|
68
|
-
#
|
69
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
70
|
-
# software under the same terms as Ruby.
|
71
|
-
#
|
72
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
73
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
74
|
-
# FOR A PARTICULAR PURPOSE.
|
75
|
-
|
76
|
-
#
|
77
|
-
module Kernel
|
78
|
-
|
79
|
-
# Easy access to method as objects, and they retain state!
|
80
|
-
#
|
81
|
-
# def hello
|
82
|
-
# puts "Hello World!"
|
83
|
-
# end
|
84
|
-
#
|
85
|
-
# m1 = method!(:hello) #=> <Method: #hello>
|
86
|
-
#
|
87
|
-
# def m1.annotate
|
88
|
-
# "simple example"
|
89
|
-
# end
|
90
|
-
#
|
91
|
-
# m2 = method!(:hello)
|
92
|
-
# m2.annotate #=> "simple example"
|
93
|
-
|
94
|
-
def method!(s)
|
95
|
-
( @__methods__ ||= {} )[s] ||= method(s)
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
|
100
|
-
# Returns the method object of the current method.
|
101
|
-
#--
|
102
|
-
# TODO Should there be a #this! ?
|
103
|
-
#++
|
104
|
-
def this
|
105
|
-
line = nil
|
106
|
-
caller(1).each do |line|
|
107
|
-
line = /\`([^\']+)\'/.match(line)
|
108
|
-
break if line
|
109
|
-
end
|
110
|
-
if line
|
111
|
-
name = line[1]
|
112
|
-
return method(name)
|
113
|
-
else
|
114
|
-
nil # ?
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
#
|
121
|
-
class Module
|
122
|
-
|
123
|
-
# Easy access to method as objects, and they retain state!
|
124
|
-
#
|
125
|
-
# module K
|
126
|
-
# def hello
|
127
|
-
# puts "Hello World!"
|
128
|
-
# end
|
129
|
-
# end
|
130
|
-
# p K.instance_method!(:hello) #=> <UnboundMethod: #hello>
|
131
|
-
#
|
132
|
-
# NOTE: This is limited to the scope of the current module/class.
|
133
|
-
|
134
|
-
def instance_method!(s)
|
135
|
-
#( @@__instance_methods__ ||= {} )[s] ||= instance_method(s) # TODO when fixed
|
136
|
-
( @__instance_methods__ ||= {} )[s] ||= instance_method(s)
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
@@ -1,162 +0,0 @@
|
|
1
|
-
# = Advisable
|
2
|
-
#
|
3
|
-
# Add before, after and around advice in dynamic fashion.
|
4
|
-
#
|
5
|
-
# == Authors
|
6
|
-
#
|
7
|
-
# * TransAspect
|
8
|
-
#
|
9
|
-
# == Copying
|
10
|
-
#
|
11
|
-
# Copyright (c) 2007 Thomas Sawyer
|
12
|
-
#
|
13
|
-
# Ruby License
|
14
|
-
#
|
15
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
16
|
-
# software under the same terms as Ruby.
|
17
|
-
#
|
18
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
19
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
20
|
-
# FOR A PARTICULAR PURPOSE.
|
21
|
-
|
22
|
-
require 'facets/1stclassmethod'
|
23
|
-
require 'facets/unboundmethod/arguments'
|
24
|
-
|
25
|
-
# = Advisable
|
26
|
-
#
|
27
|
-
# Advisable provides a means of using before, after and
|
28
|
-
# around adivce.
|
29
|
-
|
30
|
-
module Advisable
|
31
|
-
|
32
|
-
def advice_before
|
33
|
-
@advice_before ||= {} #Hash.new{|h,k| h[k] = []}
|
34
|
-
end
|
35
|
-
|
36
|
-
def advice_after
|
37
|
-
@advice_after ||= {} #Hash.new{|h,k| h[k] = []}
|
38
|
-
end
|
39
|
-
|
40
|
-
def advice_around
|
41
|
-
@advice_around ||= {} #Hash.new{|h,k| h[k] = []}
|
42
|
-
end
|
43
|
-
|
44
|
-
def before(meth, &block)
|
45
|
-
name = "#{meth}:before#{block.object_id}"
|
46
|
-
define_method(name, &block)
|
47
|
-
(advice_before[meth.to_sym] ||= []) << name
|
48
|
-
end
|
49
|
-
|
50
|
-
def after(meth, &block)
|
51
|
-
name = "#{meth}:after#{block.object_id}"
|
52
|
-
define_method(name, &block)
|
53
|
-
(advice_after[meth.to_sym] ||= []) << name
|
54
|
-
end
|
55
|
-
|
56
|
-
def around(meth, &block)
|
57
|
-
name = "#{meth}:around#{block.object_id}"
|
58
|
-
define_method(name, &block)
|
59
|
-
(advice_around[meth.to_sym] ||= []) << name
|
60
|
-
end
|
61
|
-
|
62
|
-
# Advise a method.
|
63
|
-
|
64
|
-
def advise(meth)
|
65
|
-
#return false if defined?(meth_origin)
|
66
|
-
args = instance_method(meth).arguments
|
67
|
-
|
68
|
-
module_eval(<<-END, __FILE__, __LINE__)
|
69
|
-
alias_method '#{meth}_origin', '#{meth}'
|
70
|
-
def #{meth}(#{args})
|
71
|
-
target = method!('#{meth}_origin')
|
72
|
-
|
73
|
-
unless target.advised
|
74
|
-
ancs = self.class.ancestors.select{ |anc| anc.respond_to?(:advice_before) }
|
75
|
-
target.advice_before = ancs.collect{ |anc| anc.advice_before[:'#{meth}'] }
|
76
|
-
target.advice_after = ancs.collect{ |anc| anc.advice_after[:'#{meth}'] }
|
77
|
-
target.advice_around = ancs.collect{ |anc| anc.advice_around[:'#{meth}'] }
|
78
|
-
target.advised = true
|
79
|
-
end
|
80
|
-
|
81
|
-
target.call_with_advice(self, *[#{args}])
|
82
|
-
end
|
83
|
-
END
|
84
|
-
end
|
85
|
-
|
86
|
-
#advise(:method_added)
|
87
|
-
|
88
|
-
#after :method_added do |meth|
|
89
|
-
# advise(meth) unless defined?("#{meth}_orig")
|
90
|
-
#end
|
91
|
-
|
92
|
-
def method_added(meth)
|
93
|
-
return if meth == :method_added
|
94
|
-
@added_stack ||= []
|
95
|
-
return if @added_stack.last == meth
|
96
|
-
return if /_(origin)$/ =~ meth.to_s
|
97
|
-
return if /:(before|after|around)/ =~ meth.to_s
|
98
|
-
@added_stack << meth
|
99
|
-
#return if instance_methods(false).include?("#{meth}_orig")
|
100
|
-
advise(meth)
|
101
|
-
@added_stack.pop
|
102
|
-
end
|
103
|
-
|
104
|
-
# Extensions for Method class.
|
105
|
-
|
106
|
-
module Method
|
107
|
-
|
108
|
-
attr_accessor :advised
|
109
|
-
|
110
|
-
attr_reader :advice_before
|
111
|
-
attr_reader :advice_after
|
112
|
-
attr_reader :advice_around
|
113
|
-
|
114
|
-
def advised?
|
115
|
-
@advised
|
116
|
-
end
|
117
|
-
|
118
|
-
def advice_before=(set); @advice_before = set.flatten.compact; end
|
119
|
-
def advice_after=(set) ; @advice_after = set.flatten.compact; end
|
120
|
-
def advice_around=(set); @advice_around = set.flatten.compact; end
|
121
|
-
|
122
|
-
# Call with advice.
|
123
|
-
|
124
|
-
def call_with_advice(obj, *args, &blk)
|
125
|
-
advice_before.each do |name|
|
126
|
-
#advice.call(*args, &blk)
|
127
|
-
obj.send(name, *args, &blk)
|
128
|
-
end
|
129
|
-
|
130
|
-
target = lambda{ call(*args, &blk) }
|
131
|
-
advice_around.each do |name|
|
132
|
-
target = lambda_target(obj, name, target, *args, &blk)
|
133
|
-
end
|
134
|
-
ret = target.call
|
135
|
-
|
136
|
-
advice_after.reverse_each do |name|
|
137
|
-
#advice.call(*args, &blk)
|
138
|
-
obj.send(name, *args, &blk)
|
139
|
-
end
|
140
|
-
|
141
|
-
return ret
|
142
|
-
end
|
143
|
-
|
144
|
-
private
|
145
|
-
|
146
|
-
# Using separate method for this prevents infinite loop.
|
147
|
-
|
148
|
-
def lambda_target(obj, name, target, *args, &blk)
|
149
|
-
lambda do
|
150
|
-
#advice.call(target, *args, &blk)
|
151
|
-
obj.send(name, target, *args, &blk)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
class Method #:nodoc:
|
160
|
-
include Advisable::Method
|
161
|
-
end
|
162
|
-
|
@@ -1,210 +0,0 @@
|
|
1
|
-
# = Association
|
2
|
-
#
|
3
|
-
# General binary association allows one object to be
|
4
|
-
# associated with another. It has a variety of uses,
|
5
|
-
# link-lists, simple ordered maps and mixed collections,
|
6
|
-
# among them.
|
7
|
-
#
|
8
|
-
# == Usage
|
9
|
-
#
|
10
|
-
# Associations can be used to draw simple relationships.
|
11
|
-
#
|
12
|
-
# :Apple >> :Fruit
|
13
|
-
# :Apple >> :Red
|
14
|
-
#
|
15
|
-
# :Apple.associations #=> [ :Fruit, :Red ]
|
16
|
-
#
|
17
|
-
# It can also be used for simple lists of ordered pairs.
|
18
|
-
#
|
19
|
-
# c = [ :a >> 1, :b >> 2 ]
|
20
|
-
# c.each { |k,v| puts "#{k} associated with #{v} }
|
21
|
-
#
|
22
|
-
# produces
|
23
|
-
#
|
24
|
-
# a associated with 1
|
25
|
-
# b associated with 2
|
26
|
-
#
|
27
|
-
# == Limitations
|
28
|
-
#
|
29
|
-
# The method :>> is used to construct the association.
|
30
|
-
# It is a rarely used method so it is generally available.
|
31
|
-
# But you can't use an Association while extending
|
32
|
-
# any of the following classes becuase they use #>> for
|
33
|
-
# other things.
|
34
|
-
#
|
35
|
-
# Bignum
|
36
|
-
# Fixnum
|
37
|
-
# Date
|
38
|
-
# IPAddr
|
39
|
-
# Process::Status
|
40
|
-
#
|
41
|
-
# == Author
|
42
|
-
#
|
43
|
-
# * Thomas Sawyer
|
44
|
-
#
|
45
|
-
# == License
|
46
|
-
#
|
47
|
-
# Copyright (c) 2005 Thomas Sawyer
|
48
|
-
#
|
49
|
-
# Ruby License
|
50
|
-
#
|
51
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
52
|
-
# software under the same terms as Ruby.
|
53
|
-
#
|
54
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
55
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
56
|
-
# FOR A PARTICULAR PURPOSE.
|
57
|
-
|
58
|
-
|
59
|
-
# = Association
|
60
|
-
#
|
61
|
-
# General binary association allows one object to be
|
62
|
-
# associated with another. It has a variety of uses,
|
63
|
-
# link-lists, simple ordered maps and mixed collections,
|
64
|
-
# among them.
|
65
|
-
#
|
66
|
-
# == Usage
|
67
|
-
#
|
68
|
-
# Associations can be used to draw simple relationships.
|
69
|
-
#
|
70
|
-
# :Apple >> :Fruit
|
71
|
-
# :Apple >> :Red
|
72
|
-
#
|
73
|
-
# :Apple.associations #=> [ :Fruit, :Red ]
|
74
|
-
#
|
75
|
-
# It can also be used for simple lists of ordered pairs.
|
76
|
-
#
|
77
|
-
# c = [ :a >> 1, :b >> 2 ]
|
78
|
-
# c.each { |k,v| puts "#{k} associated with #{v} }
|
79
|
-
#
|
80
|
-
# produces
|
81
|
-
#
|
82
|
-
# a associated with 1
|
83
|
-
# b associated with 2
|
84
|
-
#
|
85
|
-
# == Limitations
|
86
|
-
#
|
87
|
-
# The method :>> is used to construct the association.
|
88
|
-
# It is a rarely used method so it is generally available.
|
89
|
-
# But you can't use an Association while extending
|
90
|
-
# any of the following classes becuase they use #>> for
|
91
|
-
# other things.
|
92
|
-
#
|
93
|
-
# Bignum
|
94
|
-
# Fixnum
|
95
|
-
# Date
|
96
|
-
# IPAddr
|
97
|
-
# Process::Status
|
98
|
-
#
|
99
|
-
# TODO: Should associations be singleton?
|
100
|
-
|
101
|
-
class Association
|
102
|
-
include Comparable
|
103
|
-
|
104
|
-
class << self
|
105
|
-
# Store association references.
|
106
|
-
def reference
|
107
|
-
@reference ||= Hash.new{ |h,k,v| h[k]=[] }
|
108
|
-
end
|
109
|
-
|
110
|
-
def [](index, value)
|
111
|
-
new(index, value)
|
112
|
-
end
|
113
|
-
|
114
|
-
#def new(index, value)
|
115
|
-
# lookup[[index, value]] ||= new(index, value)
|
116
|
-
#end
|
117
|
-
|
118
|
-
#def lookup
|
119
|
-
# @lookup ||= {}
|
120
|
-
#end
|
121
|
-
end
|
122
|
-
|
123
|
-
attr_accessor :index
|
124
|
-
attr_accessor :value
|
125
|
-
|
126
|
-
def initialize(index, value=nil)
|
127
|
-
@index = index
|
128
|
-
@value = value
|
129
|
-
|
130
|
-
unless index.associations.include?(value)
|
131
|
-
index.associations << value
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def <=>(assoc)
|
136
|
-
return -1 if self.value < assoc.value
|
137
|
-
return 1 if self.value > assoc.value
|
138
|
-
return 0 if self.value == assoc.value
|
139
|
-
end
|
140
|
-
|
141
|
-
def invert!
|
142
|
-
temp = @index
|
143
|
-
@index = @value
|
144
|
-
@value = temp
|
145
|
-
end
|
146
|
-
|
147
|
-
def to_s
|
148
|
-
return "#{index.to_s}#{value.to_s}"
|
149
|
-
end
|
150
|
-
|
151
|
-
def inspect
|
152
|
-
%{#{@index.inspect} >> #{@value.inspect}}
|
153
|
-
end
|
154
|
-
|
155
|
-
def to_ary
|
156
|
-
[ @index, @value ]
|
157
|
-
end
|
158
|
-
|
159
|
-
# Object extensions.
|
160
|
-
#
|
161
|
-
module Kernel
|
162
|
-
|
163
|
-
# Define an association with +self+.
|
164
|
-
def >>(to)
|
165
|
-
Association.new(self, to)
|
166
|
-
end
|
167
|
-
|
168
|
-
def associations
|
169
|
-
Association.reference[self]
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
class Object #:nodoc:
|
177
|
-
include Association::Kernel
|
178
|
-
end
|
179
|
-
|
180
|
-
|
181
|
-
#--
|
182
|
-
# Setup the >> method in classes that use it already.
|
183
|
-
#
|
184
|
-
# This is a bad idea b/c it can cause backward compability issues.
|
185
|
-
#
|
186
|
-
# class Bignum
|
187
|
-
# alias_method( :rshift, :>>) if method_defined?(:>>)
|
188
|
-
# remove_method :>>
|
189
|
-
# end
|
190
|
-
#
|
191
|
-
# class Fixnum
|
192
|
-
# alias_method( :rshift, :>>) if method_defined?(:>>)
|
193
|
-
# remove_method :>>
|
194
|
-
# end
|
195
|
-
#
|
196
|
-
# class Date
|
197
|
-
# alias_method( :months_later, :>>) if method_defined?(:>>)
|
198
|
-
# remove_method :>>
|
199
|
-
# end
|
200
|
-
#
|
201
|
-
# class IPAddr
|
202
|
-
# alias_method( :rshift, :>>) if method_defined?(:>>)
|
203
|
-
# remove_method :>>
|
204
|
-
# end
|
205
|
-
#
|
206
|
-
# class Process::Status
|
207
|
-
# alias_method( :rshift, :>>) if method_defined?(:>>)
|
208
|
-
# remove_method :>>
|
209
|
-
# end
|
210
|
-
#++
|