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,37 @@
|
|
1
|
+
= Facets Core
|
2
|
+
|
3
|
+
Core contains the *essentials* of Facets. Core consists of a number
|
4
|
+
of generally useful core extension methods, and a couple small support
|
5
|
+
classes.
|
6
|
+
|
7
|
+
By definition Core contains anything that will load automatically when
|
8
|
+
issuing:
|
9
|
+
|
10
|
+
require 'facets'
|
11
|
+
|
12
|
+
== Facets by the Method
|
13
|
+
|
14
|
+
In the 1.0 series of Facets, all extensions were stored on a per-method
|
15
|
+
basis. This had some advantages, organization and complete fine-grain control
|
16
|
+
over requires was possible, but it proved in practice to be _too_ granular.
|
17
|
+
Some method simply too close in nature, or dependency, to go without others.
|
18
|
+
|
19
|
+
So version 2.0 has grouped the extensions method into small groups.
|
20
|
+
The library is still highly granular, but not excessively. But there's
|
21
|
+
still refinement being done in this regard. You need not worry about it
|
22
|
+
though, becuase per-method redirect libraries are provided. This is useful,
|
23
|
+
not only for backward compatability, but also if you know what method you
|
24
|
+
want, but don't recall exactly which core file it is in.
|
25
|
+
|
26
|
+
Here's an example:
|
27
|
+
|
28
|
+
require 'facets-by-method/hash/collate'
|
29
|
+
|
30
|
+
== Authors
|
31
|
+
|
32
|
+
This library more than any other part of Facets is full of contributions
|
33
|
+
from sources all across the Ruby community. For all who have code here,
|
34
|
+
the Facets Team salutes you.
|
35
|
+
|
36
|
+
For a list of names, look to the README in Facet's main documetation.
|
37
|
+
|
data/doc/manual/faq.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= Facets FAQs
|
2
|
+
|
3
|
+
Q. How do I use the core mixins on object-by-object basis?
|
4
|
+
|
5
|
+
A. One way is to use Facets' Capsule library.
|
6
|
+
|
7
|
+
require 'facets/capsule'
|
8
|
+
|
9
|
+
MyStringExts = Capsule.load('facets/string/align')::String
|
10
|
+
|
11
|
+
s = "string"
|
12
|
+
|
13
|
+
s.extend(MyStringExts)
|
14
|
+
|
15
|
+
s.align_right(10) #=> " string"
|
16
|
+
|
17
|
+
Or handle it using in-module load methods.
|
18
|
+
|
19
|
+
require 'facets/module/require'
|
20
|
+
|
21
|
+
module MyStringExts
|
22
|
+
module_load 'facets/string/align'
|
23
|
+
include String
|
24
|
+
end
|
25
|
+
|
26
|
+
s = "string"
|
27
|
+
|
28
|
+
s.extend(MyStringExts)
|
29
|
+
|
30
|
+
s.align_right(10) #=> " string"
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,112 @@
|
|
1
|
+
<html>
|
2
|
+
|
3
|
+
<head>
|
4
|
+
<title>Facets Typecast</title>
|
5
|
+
|
6
|
+
<style>
|
7
|
+
body { font: 12pt sans-serif;
|
8
|
+
padding: 0; margin: 0;
|
9
|
+
}
|
10
|
+
#container {
|
11
|
+
margin: 0 auto;
|
12
|
+
}
|
13
|
+
#title {
|
14
|
+
color: #dddddd;
|
15
|
+
border-bottom: 1px solid gray;
|
16
|
+
padding: 20px;
|
17
|
+
}
|
18
|
+
#project {
|
19
|
+
font: 22pt sans-serif;
|
20
|
+
color: black;
|
21
|
+
}
|
22
|
+
#package {
|
23
|
+
font: bold 42pt sans-serif;
|
24
|
+
color: red;
|
25
|
+
}
|
26
|
+
#corpus {
|
27
|
+
padding: 20px;
|
28
|
+
}
|
29
|
+
</style>
|
30
|
+
</head>
|
31
|
+
|
32
|
+
<body>
|
33
|
+
<div id="container">
|
34
|
+
|
35
|
+
<div id="title">
|
36
|
+
<div id="project">Facets</div>
|
37
|
+
<div id="package">Typecast</div>
|
38
|
+
</div>
|
39
|
+
|
40
|
+
<div id="corpus">
|
41
|
+
<h2>Overview</h2>
|
42
|
+
<p>Typecast provides a simple generic type conversion system. All the ruby core
|
43
|
+
conversions are available by default.</p>
|
44
|
+
|
45
|
+
<p>To implement a new type conversion, you have two choices. Given:</p>
|
46
|
+
|
47
|
+
<pre>
|
48
|
+
class CustomType
|
49
|
+
def initialize(my_var)
|
50
|
+
@my_var = my_var
|
51
|
+
end
|
52
|
+
end
|
53
|
+
</pre>
|
54
|
+
|
55
|
+
<p> 1) Define a to_class_name instance method </p>
|
56
|
+
|
57
|
+
<pre>
|
58
|
+
class CustomType
|
59
|
+
def to_string
|
60
|
+
my_var.to_s
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
c = CustomType.new 1234
|
65
|
+
s.cast_to String => "1234" (String)
|
66
|
+
</pre>
|
67
|
+
|
68
|
+
<p> 2. Define a from_class_name class method </p>
|
69
|
+
|
70
|
+
<pre>
|
71
|
+
class CustomType
|
72
|
+
def self.from_string(str)
|
73
|
+
self.new(str)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
"1234".cast_to CustomType => #<CustomType:0xb7d1958c @my_var="1234">
|
78
|
+
</pre>
|
79
|
+
|
80
|
+
<p>Those two methods are equivalent in the result. It was coded like that to
|
81
|
+
avoid the pollution of core classes with tons of to_* methods.</p>
|
82
|
+
|
83
|
+
<p>The standard methods to_s, to_f, to_i, to_a and to_sym are also used by
|
84
|
+
this system if available.</p>
|
85
|
+
|
86
|
+
<p>Usage looks like</p>
|
87
|
+
|
88
|
+
<pre>
|
89
|
+
"1234".cast_to Float => 1234.0 (Float)
|
90
|
+
Time.cast_from("6:30") => 1234.0 (Time)
|
91
|
+
</pre>
|
92
|
+
|
93
|
+
<h2>FAQ</h2>
|
94
|
+
|
95
|
+
<p>Why didn't you name the `cast_to` method to `to` ?</p>
|
96
|
+
|
97
|
+
<p>Even if it would make the syntax more friendly, I suspect it could cause
|
98
|
+
a lot of collisions with already existing code. The goal is that each
|
99
|
+
time you call cast_to, you either get your result, either a
|
100
|
+
TypeCastException.</p>
|
101
|
+
</div>
|
102
|
+
|
103
|
+
<div id="copy">
|
104
|
+
Copyright © 2004 Thomas Sawyer and all respective authors.
|
105
|
+
Ruby License
|
106
|
+
</div>
|
107
|
+
|
108
|
+
</div>
|
109
|
+
</body>
|
110
|
+
|
111
|
+
</html>
|
112
|
+
|
data/lib/core/facets.rb
CHANGED
@@ -1,11 +1,359 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
# Generated Sat Aug 22 15:28:53 -0400 2009
|
2
|
+
require 'facets/array.rb'
|
3
|
+
require 'facets/array/combination.rb'
|
4
|
+
require 'facets/array/conjoin.rb'
|
5
|
+
require 'facets/array/delete.rb'
|
6
|
+
require 'facets/array/delete_unless.rb'
|
7
|
+
require 'facets/array/delete_values.rb'
|
8
|
+
require 'facets/array/index.rb'
|
9
|
+
require 'facets/array/indexable.rb'
|
10
|
+
require 'facets/array/merge.rb'
|
11
|
+
require 'facets/array/not_empty.rb'
|
12
|
+
require 'facets/array/only.rb'
|
13
|
+
require 'facets/array/pad.rb'
|
14
|
+
require 'facets/array/permutation.rb'
|
15
|
+
require 'facets/array/product.rb'
|
16
|
+
require 'facets/array/recursively.rb'
|
17
|
+
require 'facets/array/rotate.rb'
|
18
|
+
require 'facets/array/select.rb'
|
19
|
+
require 'facets/array/splice.rb'
|
20
|
+
require 'facets/array/stackable.rb'
|
21
|
+
require 'facets/array/traverse.rb'
|
22
|
+
require 'facets/binding.rb'
|
23
|
+
require 'facets/binding/caller.rb'
|
24
|
+
require 'facets/binding/callstack.rb'
|
25
|
+
require 'facets/binding/defined.rb'
|
26
|
+
require 'facets/binding/eval.rb'
|
27
|
+
require 'facets/binding/local_variables.rb'
|
28
|
+
require 'facets/binding/opvars.rb'
|
29
|
+
require 'facets/binding/self.rb'
|
30
|
+
require 'facets/bitmask.rb'
|
31
|
+
require 'facets/blank.rb'
|
32
|
+
require 'facets/boolean.rb'
|
33
|
+
require 'facets/cattr.rb'
|
34
|
+
require 'facets/class.rb'
|
35
|
+
require 'facets/class/cattr.rb'
|
36
|
+
require 'facets/class/cattr_accessor.rb'
|
37
|
+
require 'facets/class/cattr_reader.rb'
|
38
|
+
require 'facets/class/cattr_writer.rb'
|
39
|
+
require 'facets/class/descendents.rb'
|
40
|
+
require 'facets/class/methodize.rb'
|
41
|
+
require 'facets/class/pathize.rb'
|
42
|
+
require 'facets/class/prepend.rb'
|
43
|
+
require 'facets/class/subclasses.rb'
|
44
|
+
require 'facets/class/to_proc.rb'
|
45
|
+
require 'facets/comparable.rb'
|
46
|
+
require 'facets/comparable/at_least.rb'
|
47
|
+
require 'facets/comparable/at_most.rb'
|
48
|
+
require 'facets/comparable/bound.rb'
|
49
|
+
require 'facets/comparable/cap.rb'
|
50
|
+
require 'facets/comparable/clip.rb'
|
51
|
+
require 'facets/comparable/cmp.rb'
|
52
|
+
require 'facets/comparable/comparable.rb'
|
53
|
+
require 'facets/denumerable.rb'
|
54
|
+
require 'facets/dir.rb'
|
55
|
+
require 'facets/dir/ascend.rb'
|
56
|
+
require 'facets/dir/descend.rb'
|
57
|
+
require 'facets/dir/multiglob.rb'
|
58
|
+
require 'facets/dir/parent.rb'
|
59
|
+
require 'facets/dir/recurse.rb'
|
60
|
+
require 'facets/duplicable.rb'
|
61
|
+
require 'facets/enumerable.rb'
|
62
|
+
require 'facets/enumerable/accumulate.rb'
|
63
|
+
require 'facets/enumerable/cluster_by.rb'
|
64
|
+
require 'facets/enumerable/collect.rb'
|
65
|
+
require 'facets/enumerable/commonality.rb'
|
66
|
+
require 'facets/enumerable/compact_map.rb'
|
67
|
+
require 'facets/enumerable/count.rb'
|
68
|
+
require 'facets/enumerable/defer.rb'
|
69
|
+
require 'facets/enumerable/divide.rb'
|
70
|
+
require 'facets/enumerable/duplicates.rb'
|
71
|
+
require 'facets/enumerable/each_by.rb'
|
72
|
+
require 'facets/enumerable/entropy.rb'
|
73
|
+
require 'facets/enumerable/every.rb'
|
74
|
+
require 'facets/enumerable/ewise.rb'
|
75
|
+
require 'facets/enumerable/filter.rb'
|
76
|
+
require 'facets/enumerable/frequency.rb'
|
77
|
+
require 'facets/enumerable/graph.rb'
|
78
|
+
require 'facets/enumerable/group_by.rb'
|
79
|
+
require 'facets/enumerable/inject.rb'
|
80
|
+
require 'facets/enumerable/map_send.rb'
|
81
|
+
require 'facets/enumerable/map_with_index.rb'
|
82
|
+
require 'facets/enumerable/mash.rb'
|
83
|
+
require 'facets/enumerable/mode.rb'
|
84
|
+
require 'facets/enumerable/modulate.rb'
|
85
|
+
require 'facets/enumerable/none.rb'
|
86
|
+
require 'facets/enumerable/occur.rb'
|
87
|
+
require 'facets/enumerable/one.rb'
|
88
|
+
require 'facets/enumerable/per.rb'
|
89
|
+
require 'facets/enumerable/probability.rb'
|
90
|
+
require 'facets/enumerable/split.rb'
|
91
|
+
require 'facets/enumerable/sum.rb'
|
92
|
+
require 'facets/enumerable/take.rb'
|
93
|
+
require 'facets/enumerable/uniq_by.rb'
|
94
|
+
require 'facets/exception.rb'
|
95
|
+
require 'facets/exception/detail.rb'
|
96
|
+
require 'facets/exception/raised.rb'
|
97
|
+
require 'facets/exception/suppress.rb'
|
98
|
+
require 'facets/file.rb'
|
99
|
+
require 'facets/file/append.rb'
|
100
|
+
require 'facets/file/create.rb'
|
101
|
+
require 'facets/file/null.rb'
|
102
|
+
require 'facets/file/read.rb'
|
103
|
+
require 'facets/file/rewrite.rb'
|
104
|
+
require 'facets/file/rootname.rb'
|
105
|
+
require 'facets/file/split_all.rb'
|
106
|
+
require 'facets/file/split_root.rb'
|
107
|
+
require 'facets/file/write.rb'
|
108
|
+
require 'facets/file/writelines.rb'
|
109
|
+
require 'facets/filetest.rb'
|
110
|
+
require 'facets/filetest/root.rb'
|
111
|
+
require 'facets/float.rb'
|
112
|
+
require 'facets/float/round.rb'
|
113
|
+
require 'facets/functor.rb'
|
114
|
+
require 'facets/hash.rb'
|
115
|
+
require 'facets/hash/alias.rb'
|
116
|
+
require 'facets/hash/argumentize.rb'
|
117
|
+
require 'facets/hash/at.rb'
|
118
|
+
require 'facets/hash/autonew.rb'
|
119
|
+
require 'facets/hash/collate.rb'
|
120
|
+
require 'facets/hash/dearray_values.rb'
|
121
|
+
require 'facets/hash/delete.rb'
|
122
|
+
require 'facets/hash/diff.rb'
|
123
|
+
require 'facets/hash/except.rb'
|
124
|
+
require 'facets/hash/group_by_value.rb'
|
125
|
+
require 'facets/hash/insert.rb'
|
126
|
+
require 'facets/hash/inverse.rb'
|
127
|
+
require 'facets/hash/join.rb'
|
128
|
+
require 'facets/hash/keys.rb'
|
129
|
+
require 'facets/hash/mash.rb'
|
130
|
+
require 'facets/hash/merge.rb'
|
131
|
+
require 'facets/hash/new_with.rb'
|
132
|
+
require 'facets/hash/op.rb'
|
133
|
+
require 'facets/hash/op_add.rb'
|
134
|
+
require 'facets/hash/op_and.rb'
|
135
|
+
require 'facets/hash/op_mul.rb'
|
136
|
+
require 'facets/hash/op_or.rb'
|
137
|
+
require 'facets/hash/op_push.rb'
|
138
|
+
require 'facets/hash/op_sub.rb'
|
139
|
+
require 'facets/hash/recursive_merge.rb'
|
140
|
+
require 'facets/hash/recursively.rb'
|
141
|
+
require 'facets/hash/rekey.rb'
|
142
|
+
require 'facets/hash/replace_each.rb'
|
143
|
+
require 'facets/hash/select.rb'
|
144
|
+
require 'facets/hash/slice.rb'
|
145
|
+
require 'facets/hash/stringify_keys.rb'
|
146
|
+
require 'facets/hash/swap.rb'
|
147
|
+
require 'facets/hash/symbolize_keys.rb'
|
148
|
+
require 'facets/hash/to_h.rb'
|
149
|
+
require 'facets/hash/to_options.rb'
|
150
|
+
require 'facets/hash/to_proc.rb'
|
151
|
+
require 'facets/hash/to_struct.rb'
|
152
|
+
require 'facets/hash/traverse.rb'
|
153
|
+
require 'facets/hash/update.rb'
|
154
|
+
require 'facets/hash/update_each.rb'
|
155
|
+
require 'facets/hash/update_keys.rb'
|
156
|
+
require 'facets/hash/update_values.rb'
|
157
|
+
require 'facets/hash/weave.rb'
|
158
|
+
require 'facets/hash/zipnew.rb'
|
159
|
+
require 'facets/indexable.rb'
|
160
|
+
require 'facets/integer.rb'
|
161
|
+
require 'facets/integer/even.rb'
|
162
|
+
require 'facets/integer/factorial.rb'
|
163
|
+
require 'facets/integer/length.rb'
|
164
|
+
require 'facets/integer/multiple.rb'
|
165
|
+
require 'facets/integer/odd.rb'
|
166
|
+
require 'facets/integer/of.rb'
|
167
|
+
require 'facets/integer/ordinal.rb'
|
168
|
+
require 'facets/kernel.rb'
|
169
|
+
require 'facets/kernel/__callee__.rb'
|
170
|
+
require 'facets/kernel/__class__.rb'
|
171
|
+
require 'facets/kernel/__dir__.rb'
|
172
|
+
require 'facets/kernel/__get__.rb'
|
173
|
+
require 'facets/kernel/__here__.rb'
|
174
|
+
require 'facets/kernel/__method__.rb'
|
175
|
+
require 'facets/kernel/__set__.rb'
|
176
|
+
require 'facets/kernel/as.rb'
|
177
|
+
require 'facets/kernel/ask.rb'
|
178
|
+
require 'facets/kernel/attr_singleton.rb'
|
179
|
+
require 'facets/kernel/callstack.rb'
|
180
|
+
require 'facets/kernel/complete.rb'
|
181
|
+
require 'facets/kernel/constant.rb'
|
182
|
+
require 'facets/kernel/d.rb'
|
183
|
+
require 'facets/kernel/deep_copy.rb'
|
184
|
+
require 'facets/kernel/demo.rb'
|
185
|
+
require 'facets/kernel/equate.rb'
|
186
|
+
require 'facets/kernel/ergo.rb'
|
187
|
+
require 'facets/kernel/extension.rb'
|
188
|
+
require 'facets/kernel/here.rb'
|
189
|
+
require 'facets/kernel/identical.rb'
|
190
|
+
require 'facets/kernel/in.rb'
|
191
|
+
require 'facets/kernel/instance_assign.rb'
|
192
|
+
require 'facets/kernel/instance_class.rb'
|
193
|
+
require 'facets/kernel/instance_exec.rb'
|
194
|
+
require 'facets/kernel/instance_send.rb'
|
195
|
+
require 'facets/kernel/instance_variables.rb'
|
196
|
+
require 'facets/kernel/maybe.rb'
|
197
|
+
require 'facets/kernel/method.rb'
|
198
|
+
require 'facets/kernel/not_nil.rb'
|
199
|
+
require 'facets/kernel/object_class.rb'
|
200
|
+
require 'facets/kernel/object_hexid.rb'
|
201
|
+
require 'facets/kernel/object_send.rb'
|
202
|
+
require 'facets/kernel/object_state.rb'
|
203
|
+
require 'facets/kernel/p.rb'
|
204
|
+
require 'facets/kernel/populate.rb'
|
205
|
+
require 'facets/kernel/qua_class.rb'
|
206
|
+
require 'facets/kernel/require_all.rb'
|
207
|
+
require 'facets/kernel/require_local.rb'
|
208
|
+
require 'facets/kernel/require_relative.rb'
|
209
|
+
require 'facets/kernel/resc.rb'
|
210
|
+
require 'facets/kernel/respond.rb'
|
211
|
+
require 'facets/kernel/returning.rb'
|
212
|
+
require 'facets/kernel/silence.rb'
|
213
|
+
require 'facets/kernel/singleton_class.rb'
|
214
|
+
require 'facets/kernel/source_location.rb'
|
215
|
+
require 'facets/kernel/tap.rb'
|
216
|
+
require 'facets/kernel/try.rb'
|
217
|
+
require 'facets/kernel/val.rb'
|
218
|
+
require 'facets/kernel/with.rb'
|
219
|
+
require 'facets/lazy.rb'
|
220
|
+
require 'facets/matchdata.rb'
|
221
|
+
require 'facets/matchdata/match.rb'
|
222
|
+
require 'facets/matchdata/matchset.rb'
|
223
|
+
require 'facets/metaid.rb'
|
224
|
+
require 'facets/module.rb'
|
225
|
+
require 'facets/module/abstract.rb'
|
226
|
+
require 'facets/module/alias_accessor.rb'
|
227
|
+
require 'facets/module/alias_method_chain.rb'
|
228
|
+
require 'facets/module/alias_module_function.rb'
|
229
|
+
require 'facets/module/ancestor.rb'
|
230
|
+
require 'facets/module/attr_setter.rb'
|
231
|
+
require 'facets/module/basename.rb'
|
232
|
+
require 'facets/module/can.rb'
|
233
|
+
require 'facets/module/class.rb'
|
234
|
+
require 'facets/module/conflict.rb'
|
235
|
+
require 'facets/module/extend.rb'
|
236
|
+
require 'facets/module/include_function_module.rb'
|
237
|
+
require 'facets/module/instance_method.rb'
|
238
|
+
require 'facets/module/instance_methods.rb'
|
239
|
+
require 'facets/module/integrate.rb'
|
240
|
+
require 'facets/module/is.rb'
|
241
|
+
require 'facets/module/methodize.rb'
|
242
|
+
require 'facets/module/modspace.rb'
|
243
|
+
require 'facets/module/module_load.rb'
|
244
|
+
require 'facets/module/module_require.rb'
|
245
|
+
require 'facets/module/nesting.rb'
|
246
|
+
require 'facets/module/op.rb'
|
247
|
+
require 'facets/module/pathize.rb'
|
248
|
+
require 'facets/module/prepend.rb'
|
249
|
+
require 'facets/module/redefine_method.rb'
|
250
|
+
require 'facets/module/redirect_method.rb'
|
251
|
+
require 'facets/module/rename_method.rb'
|
252
|
+
require 'facets/module/revise.rb'
|
253
|
+
require 'facets/module/spacename.rb'
|
254
|
+
require 'facets/module/wrap_method.rb'
|
255
|
+
require 'facets/nilclass.rb'
|
256
|
+
require 'facets/nilclass/ergo.rb'
|
257
|
+
require 'facets/nilclass/to_f.rb'
|
258
|
+
require 'facets/numeric.rb'
|
259
|
+
require 'facets/numeric/approx.rb'
|
260
|
+
require 'facets/numeric/distance.rb'
|
261
|
+
require 'facets/numeric/round.rb'
|
262
|
+
require 'facets/objectspace.rb'
|
263
|
+
require 'facets/objectspace/classes.rb'
|
264
|
+
require 'facets/objectspace/op_fetch.rb'
|
265
|
+
require 'facets/proc.rb'
|
266
|
+
require 'facets/proc/bind.rb'
|
267
|
+
require 'facets/proc/compose.rb'
|
268
|
+
require 'facets/proc/curry.rb'
|
269
|
+
require 'facets/proc/to_method.rb'
|
270
|
+
require 'facets/proc/update.rb'
|
271
|
+
require 'facets/range.rb'
|
272
|
+
require 'facets/range/combine.rb'
|
273
|
+
require 'facets/range/overlap.rb'
|
274
|
+
require 'facets/range/to_r.rb'
|
275
|
+
require 'facets/range/umbrella.rb'
|
276
|
+
require 'facets/range/within.rb'
|
277
|
+
require 'facets/regexp.rb'
|
278
|
+
require 'facets/regexp/arity.rb'
|
279
|
+
require 'facets/regexp/to_re.rb'
|
280
|
+
require 'facets/stackable.rb'
|
281
|
+
require 'facets/string.rb'
|
282
|
+
require 'facets/string/align.rb'
|
283
|
+
require 'facets/string/bracket.rb'
|
284
|
+
require 'facets/string/bytes.rb'
|
285
|
+
require 'facets/string/camelcase.rb'
|
286
|
+
require 'facets/string/capitalized.rb'
|
287
|
+
require 'facets/string/chars.rb'
|
288
|
+
require 'facets/string/chomp.rb'
|
289
|
+
require 'facets/string/cleave.rb'
|
290
|
+
require 'facets/string/compress_lines.rb'
|
291
|
+
require 'facets/string/contains.rb'
|
292
|
+
require 'facets/string/divide.rb'
|
293
|
+
require 'facets/string/each_char.rb'
|
294
|
+
require 'facets/string/each_word.rb'
|
295
|
+
require 'facets/string/end_with.rb'
|
296
|
+
require 'facets/string/expand_tab.rb'
|
297
|
+
require 'facets/string/file.rb'
|
298
|
+
require 'facets/string/fold.rb'
|
299
|
+
require 'facets/string/indent.rb'
|
300
|
+
require 'facets/string/interpolate.rb'
|
301
|
+
require 'facets/string/line_wrap.rb'
|
302
|
+
require 'facets/string/lines.rb'
|
303
|
+
require 'facets/string/lowercase.rb'
|
304
|
+
require 'facets/string/margin.rb'
|
305
|
+
require 'facets/string/methodize.rb'
|
306
|
+
require 'facets/string/modulize.rb'
|
307
|
+
require 'facets/string/mscan.rb'
|
308
|
+
require 'facets/string/natcmp.rb'
|
309
|
+
require 'facets/string/nchar.rb'
|
310
|
+
require 'facets/string/op_sub.rb'
|
311
|
+
require 'facets/string/outdent.rb'
|
312
|
+
require 'facets/string/pathize.rb'
|
313
|
+
require 'facets/string/range.rb'
|
314
|
+
require 'facets/string/rewrite.rb'
|
315
|
+
require 'facets/string/shatter.rb'
|
316
|
+
require 'facets/string/snakecase.rb'
|
317
|
+
require 'facets/string/splice.rb'
|
318
|
+
require 'facets/string/start_with.rb'
|
319
|
+
require 'facets/string/subtract.rb'
|
320
|
+
require 'facets/string/tab.rb'
|
321
|
+
require 'facets/string/tabto.rb'
|
322
|
+
require 'facets/string/titlecase.rb'
|
323
|
+
require 'facets/string/to_re.rb'
|
324
|
+
require 'facets/string/underscore.rb'
|
325
|
+
require 'facets/string/unfold.rb'
|
326
|
+
require 'facets/string/uppercase.rb'
|
327
|
+
require 'facets/string/variablize.rb'
|
328
|
+
require 'facets/string/word_wrap.rb'
|
329
|
+
require 'facets/string/words.rb'
|
330
|
+
require 'facets/string/xor.rb'
|
331
|
+
require 'facets/struct.rb'
|
332
|
+
require 'facets/struct/attributes.rb'
|
333
|
+
require 'facets/symbol.rb'
|
334
|
+
require 'facets/symbol/chomp.rb'
|
335
|
+
require 'facets/symbol/generate.rb'
|
336
|
+
require 'facets/symbol/not.rb'
|
337
|
+
require 'facets/symbol/plain.rb'
|
338
|
+
require 'facets/symbol/query.rb'
|
339
|
+
require 'facets/symbol/re_s.rb'
|
340
|
+
require 'facets/symbol/setter.rb'
|
341
|
+
require 'facets/symbol/succ.rb'
|
342
|
+
require 'facets/symbol/thrown.rb'
|
343
|
+
require 'facets/symbol/to_proc.rb'
|
344
|
+
require 'facets/symbol/variablize.rb'
|
345
|
+
require 'facets/time.rb'
|
346
|
+
require 'facets/time/advance.rb'
|
347
|
+
require 'facets/time/ago.rb'
|
348
|
+
require 'facets/time/change.rb'
|
349
|
+
require 'facets/time/elapse.rb'
|
350
|
+
require 'facets/time/hence.rb'
|
351
|
+
require 'facets/time/round.rb'
|
352
|
+
require 'facets/time/set.rb'
|
353
|
+
require 'facets/time/stamp.rb'
|
354
|
+
require 'facets/time/to_time.rb'
|
355
|
+
require 'facets/time/trunc.rb'
|
356
|
+
require 'facets/to_hash.rb'
|
357
|
+
require 'facets/unboundmethod.rb'
|
358
|
+
require 'facets/unboundmethod/arguments.rb'
|
359
|
+
require 'facets/unboundmethod/name.rb'
|