facets 2.6.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,6 +1,6 @@
|
|
1
1
|
class Integer
|
2
2
|
|
3
|
-
|
3
|
+
unless method_defined?(:odd?) # 1.8.7+
|
4
4
|
|
5
5
|
# Returns true if this integer is odd, false otherwise.
|
6
6
|
#
|
@@ -17,6 +17,10 @@ class Integer
|
|
17
17
|
self & 1 == 1
|
18
18
|
end
|
19
19
|
|
20
|
+
end
|
21
|
+
|
22
|
+
unless method_defined?(:even?) # 1.8.7+
|
23
|
+
|
20
24
|
# Returns true if this integer is even, false otherwise.
|
21
25
|
#
|
22
26
|
# 2.even? #=> true
|
@@ -1,12 +1,22 @@
|
|
1
1
|
module Kernel
|
2
2
|
|
3
|
-
# Similar to __FILE__
|
4
|
-
#
|
3
|
+
# Similar to __FILE__, __DIR__ provides the directory
|
4
|
+
# path to the current executing script.
|
5
5
|
#
|
6
6
|
# CREDIT: Trans
|
7
7
|
|
8
8
|
def __DIR__
|
9
|
-
|
9
|
+
c = caller.first
|
10
|
+
return nil unless c.rindex(/:\d+(:in `.*')?$/)
|
11
|
+
file = $` # File.dirname(c)
|
12
|
+
return nil if /\A\((.*)\)/ =~ file # eval, etc.
|
13
|
+
#File.expand_path(File.dirname(file))
|
14
|
+
File.dirname(file)
|
10
15
|
end
|
11
16
|
|
17
|
+
#def __DIR__
|
18
|
+
# (/^(.+)?:\d+/ =~ caller[0]) ? File.dirname($1) : nil
|
19
|
+
#end
|
20
|
+
|
12
21
|
end
|
22
|
+
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
module Kernel
|
2
2
|
|
3
|
-
|
3
|
+
unless method_defined?(:__method__) # 1.8.7+
|
4
4
|
|
5
5
|
# Retreive the current running method name.
|
6
6
|
#
|
@@ -15,6 +15,12 @@ unless (RUBY_VERSION[0,3] == '1.9')
|
|
15
15
|
/\`([^\']+)\'/.match(caller(1).first)[1].to_sym
|
16
16
|
end
|
17
17
|
|
18
|
+
private :__method__
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
unless method_defined?(:__callee__) # 1.9+ # TODO: Is this so?
|
23
|
+
|
18
24
|
# Retreive the current running method name.
|
19
25
|
#
|
20
26
|
# def tester; __callee__; end
|
@@ -28,7 +34,7 @@ unless (RUBY_VERSION[0,3] == '1.9')
|
|
28
34
|
/\`([^\']+)\'/.match(caller(1).first)[1].to_sym
|
29
35
|
end
|
30
36
|
|
31
|
-
private :__callee__
|
37
|
+
private :__callee__
|
32
38
|
|
33
39
|
end
|
34
40
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
# Broad equality.
|
4
|
+
#
|
5
|
+
# Checks to see if the object +x+ is in any
|
6
|
+
# way equal to the reciever, starting with the
|
7
|
+
# identity #equals? and ending with #===.
|
8
|
+
#
|
9
|
+
def equate?(x)
|
10
|
+
equal?(x) || eql?(x) || self == x || self === x
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class Object #module Kernel
|
2
2
|
|
3
|
-
unless
|
3
|
+
unless method_defined?(:instance_exec) # 1.9
|
4
4
|
|
5
5
|
module InstanceExecMethods #:nodoc:
|
6
6
|
end
|
7
|
+
|
7
8
|
include InstanceExecMethods
|
8
9
|
|
9
10
|
# Evaluate the block with the given arguments within the context of
|
@@ -0,0 +1,49 @@
|
|
1
|
+
$FIRST_CLASS_METHODS = Hash.new{ |h,k| h[k] = {} }
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
|
5
|
+
# Easy access to method as object, 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
|
+
def method!(s)
|
21
|
+
#( @__methods__ ||= {} )[s.to_sym] ||= method(s)
|
22
|
+
$FIRST_CLASS_METHODS[self][s.to_sym] ||= method(s)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
# Should 1st Class Methods be part of Ruby proper?
|
28
|
+
#
|
29
|
+
# Perhaps the best solution would be using the notation
|
30
|
+
# <tt>::ameth</tt>. This would require some minor changes
|
31
|
+
# to Ruby, but with few backward incompatabilites if
|
32
|
+
# parantheticals revert back to the actual method invocation.
|
33
|
+
# Although this later stipulation means capitalized methods
|
34
|
+
# would not be accessible in this way b/c they would intefere with
|
35
|
+
# constant lookup. It's a trade off.
|
36
|
+
#
|
37
|
+
# Current Proposed Alternate
|
38
|
+
# ----------------- ------------------ -------------------
|
39
|
+
# Foo.Bar() method call method call method call
|
40
|
+
# Foo.Bar method call method call method call
|
41
|
+
# Foo.bar() method call method call method call
|
42
|
+
# Foo.bar method call method call method call
|
43
|
+
# Foo::Bar() method call method call 1st class method
|
44
|
+
# Foo::Bar constant lookup constant lookup constant lookup
|
45
|
+
# Foo::bar() method call method call 1st class method
|
46
|
+
# Foo::bar method call 1st class method 1st class method
|
47
|
+
#
|
48
|
+
# Then again this dosen't address bound versus unbound.
|
49
|
+
|
@@ -20,9 +20,9 @@ module Kernel
|
|
20
20
|
def object_send(name,*args,&blk)
|
21
21
|
#instance_eval "self.#{name}(*args)"
|
22
22
|
if respond_to?(name)
|
23
|
-
|
23
|
+
__send__(name,*args,&blk)
|
24
24
|
else #if respond_to?(:method_missing)
|
25
|
-
method_missing
|
25
|
+
__send__(:method_missing,name,*args,&blk)
|
26
26
|
#else
|
27
27
|
# raise NoMethodError
|
28
28
|
end
|
@@ -1,50 +1,61 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
def
|
4
|
-
if
|
1
|
+
class Object
|
2
|
+
# Get state of object.
|
3
|
+
def object_state(data=nil)
|
4
|
+
if data
|
5
5
|
instance_variables.each do |iv|
|
6
6
|
name = iv.to_s.sub(/^[@]/, '').to_sym
|
7
|
-
instance_variable_set(iv,
|
7
|
+
instance_variable_set(iv, snap[name])
|
8
8
|
end
|
9
9
|
else
|
10
|
-
data =
|
10
|
+
data = {}
|
11
11
|
instance_variables.each do |iv|
|
12
12
|
name = iv.to_s.sub(/^[@]/, '').to_sym
|
13
13
|
data[name] = instance_variable_get(iv)
|
14
14
|
end
|
15
|
-
|
15
|
+
snap
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
# Replace state of object.
|
20
|
+
def replace(data)
|
21
|
+
instance_variables.each do |iv|
|
22
|
+
name = iv.to_s.sub(/^[@]/, '').to_sym
|
23
|
+
instance_variable_set(iv, data[name])
|
24
|
+
end
|
25
|
+
end
|
19
26
|
end
|
20
27
|
|
21
28
|
class Array
|
22
|
-
def
|
29
|
+
def object_state(data=nil)
|
23
30
|
data ? replace(data) : dup
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
27
34
|
class String
|
28
|
-
def
|
35
|
+
def object_state(data=nil)
|
29
36
|
data ? replace(data) : dup
|
30
37
|
end
|
31
38
|
end
|
32
39
|
|
33
40
|
class Hash
|
34
|
-
def
|
41
|
+
def object_state(data=nil)
|
35
42
|
data ? replace(data) : dup
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
39
46
|
class Struct
|
40
|
-
def
|
47
|
+
def object_state(data=nil)
|
41
48
|
if data
|
42
49
|
data.each_pair {|k,v| send(k.to_s + "=", v)}
|
43
50
|
else
|
44
|
-
data =
|
51
|
+
data = {}
|
45
52
|
each_pair{|k,v| data[k] = v}
|
46
53
|
data
|
47
54
|
end
|
48
55
|
end
|
56
|
+
|
57
|
+
def replace(snap)
|
58
|
+
snap.each_pair {|k,v| send(k.to_s + "=", v)}
|
59
|
+
end
|
49
60
|
end
|
50
61
|
|
@@ -5,12 +5,17 @@ module Kernel
|
|
5
5
|
#
|
6
6
|
# require_all 'facets/time/*'
|
7
7
|
#
|
8
|
+
# You can also you #require_all relative to the
|
9
|
+
# current script simply by using __DIR__.
|
10
|
+
#
|
11
|
+
# require_all(__DIR__ + '/foo/*')
|
12
|
+
#
|
8
13
|
def require_all(pat)
|
9
14
|
$LOAD_PATH.each do |path|
|
10
15
|
fs = Dir[File.join(path,pat)]
|
11
16
|
unless fs.empty?
|
12
17
|
fs.each { |f|
|
13
|
-
Kernel.require(
|
18
|
+
Kernel.require(f) unless File.directory?(f)
|
14
19
|
}
|
15
20
|
break;
|
16
21
|
end
|
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'facets/kernel/require_relative'
|
2
|
+
|
3
|
+
=begin
|
1
4
|
module Kernel
|
2
5
|
|
3
6
|
# Require file from same dir as calling script.
|
4
7
|
#
|
5
8
|
# require_local 'templib'
|
6
9
|
#
|
10
|
+
# CREDIT: Paul Brannan
|
11
|
+
#
|
7
12
|
def require_local(fname)
|
8
13
|
#fdir = File.expand_path( File.dirname( caller[0] ) )
|
9
14
|
fdir = File.dirname( caller[0] )
|
@@ -14,6 +19,8 @@ module Kernel
|
|
14
19
|
#
|
15
20
|
# load_local 'templib'
|
16
21
|
#
|
22
|
+
# CREDIT: Paul Brannan
|
23
|
+
#
|
17
24
|
def load_local(fname, safe=nil)
|
18
25
|
#fdir = File.expand_path( File.dirname( caller[0] ) )
|
19
26
|
fdir = File.dirname( caller[0] )
|
@@ -21,4 +28,4 @@ module Kernel
|
|
21
28
|
end
|
22
29
|
|
23
30
|
end
|
24
|
-
|
31
|
+
=end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
unless method_defined?(:require_relative) # 1.9
|
4
|
+
|
5
|
+
# Require file from same dir as calling script.
|
6
|
+
#
|
7
|
+
# require_local 'templib'
|
8
|
+
#
|
9
|
+
# CREDIT: Paul Brannan, Pragmatic Programmers
|
10
|
+
#
|
11
|
+
def require_relative(relative_feature)
|
12
|
+
c = caller.first
|
13
|
+
fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
|
14
|
+
file = $` # File.dirname(c)
|
15
|
+
if /\A\((.*)\)/ =~ file # eval, etc.
|
16
|
+
raise LoadError, "require_relative is called in #{$1}"
|
17
|
+
end
|
18
|
+
absolute = File.expand_path(relative_feature, File.dirname(file))
|
19
|
+
require absolute
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
# Backward compatability.
|
25
|
+
alias_method :require_local, :require_relative
|
26
|
+
|
27
|
+
unless method_defined?(:load_relative) # 1.9
|
28
|
+
|
29
|
+
# Load file from same dir as calling script.
|
30
|
+
#
|
31
|
+
# load_local 'templib'
|
32
|
+
#
|
33
|
+
# CREDIT: Paul Brannan, Pragmatic Programmers
|
34
|
+
#
|
35
|
+
def load_relative(relative_feature, safe=nil)
|
36
|
+
c = caller.first
|
37
|
+
fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
|
38
|
+
file = $` # File.dirname(c)
|
39
|
+
if /\A\((.*)\)/ =~ file # eval, etc.
|
40
|
+
raise LoadError, "require_relative is called in #{$1}"
|
41
|
+
end
|
42
|
+
absolute = File.expand_path(relative_feature, File.dirname(file))
|
43
|
+
load absolute, safe
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
# Backward compatability.
|
49
|
+
alias_method :load_local, :load_relative
|
50
|
+
|
51
|
+
end
|
52
|
+
|
@@ -1,9 +1,12 @@
|
|
1
|
-
|
1
|
+
module Kernel
|
2
2
|
|
3
|
-
|
3
|
+
unless method_defined?(:tap) # 1.8.7+
|
4
4
|
|
5
5
|
# The tap K-Combinator. This yields self -and- returns self.
|
6
|
-
|
6
|
+
#
|
7
|
+
# Note, Ruby 1.9+ does not appear to support the zero arity
|
8
|
+
# instance_eval option.
|
9
|
+
#
|
7
10
|
def tap(&b)
|
8
11
|
if block_given?
|
9
12
|
b.arity == 1 ? yield(self) : instance_eval(&b)
|
@@ -11,11 +14,11 @@ unless (RUBY_VERSION[0,3] == '1.9')
|
|
11
14
|
self
|
12
15
|
end
|
13
16
|
|
14
|
-
#
|
17
|
+
# == Future definition?
|
15
18
|
#
|
16
|
-
#
|
19
|
+
# This is a consideration for a future #tap using Functor:
|
17
20
|
#
|
18
|
-
#
|
21
|
+
# require 'facets/functor'
|
19
22
|
#
|
20
23
|
# def tap(&b)
|
21
24
|
# if block_given?
|
@@ -25,6 +28,10 @@ unless (RUBY_VERSION[0,3] == '1.9')
|
|
25
28
|
# Functor.new{ |op, *args| self.send(op, *args); self }
|
26
29
|
# end
|
27
30
|
# end
|
31
|
+
#
|
32
|
+
# It would allow a single call, before returning the original.
|
33
|
+
# However there are not very many useful things you can do with
|
34
|
+
# that.
|
28
35
|
|
29
36
|
end
|
30
37
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Module
|
2
|
+
|
3
|
+
# Create an attribute method for both getting
|
4
|
+
# and setting an instance variable.
|
5
|
+
#
|
6
|
+
# attr_setter :a
|
7
|
+
#
|
8
|
+
# _is equivalent to_
|
9
|
+
#
|
10
|
+
# def a(*args)
|
11
|
+
# if args.size > 0
|
12
|
+
# @a = args[0]
|
13
|
+
# self
|
14
|
+
# else
|
15
|
+
# @a
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# CREDIT: Trans
|
20
|
+
|
21
|
+
def attr_setter(*args)
|
22
|
+
code, made = '', []
|
23
|
+
args.each do |a|
|
24
|
+
code << %{
|
25
|
+
def #{a}(*args)
|
26
|
+
args.size > 0 ? ( @#{a}=args[0] ; self ) : @#{a}
|
27
|
+
end
|
28
|
+
}
|
29
|
+
made << "#{a}".to_sym
|
30
|
+
end
|
31
|
+
module_eval code
|
32
|
+
made
|
33
|
+
end
|
34
|
+
|
35
|
+
# Alias an accessor. This create an alias for
|
36
|
+
# both a reader and a writer.
|
37
|
+
#
|
38
|
+
# class X
|
39
|
+
# attr_accessor :a
|
40
|
+
# alias_accessor :b, :a
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# x = X.new
|
44
|
+
# x.b = 1
|
45
|
+
# x.a #=> 1
|
46
|
+
#
|
47
|
+
# CREDIT: Trans
|
48
|
+
|
49
|
+
def alias_setter(*args)
|
50
|
+
args = args - [orig]
|
51
|
+
args.each do |name|
|
52
|
+
alias_method(name, orig)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|