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
@@ -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
|
-
#
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
52
|
-
|
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'
|
@@ -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 << "
|
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
|
-
|
1
|
+
class String
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
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 #=> "
|
15
|
-
# "camel/case".camelcase
|
16
|
-
# "
|
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)([
|
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
|
-
|
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,13 +1,20 @@
|
|
1
|
-
|
1
|
+
class String
|
2
2
|
|
3
|
-
|
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
|
-
|
10
|
-
|
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
|
-
|
1
|
+
class String
|
2
2
|
|
3
|
-
|
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
|
-
|
1
|
+
class Symbol
|
2
2
|
|
3
|
-
|
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
|
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
|
-
|
1
|
+
class Symbol
|
2
2
|
|
3
|
-
|
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
|
+
|
data/lib/core/facets/to_hash.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require 'enumerator'
|
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
|
-
|
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
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
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
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
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
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
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
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
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
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
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
|