facets 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.index +11 -7
- data/CONTRIBUTING.md +112 -0
- data/HISTORY.md +38 -0
- data/{README.rdoc → README.md} +59 -59
- data/demo/core/array/after.md +13 -0
- data/demo/core/array/arrange.md +17 -0
- data/demo/core/array/before.md +14 -0
- data/demo/core/array/collapse.md +15 -0
- data/demo/core/array/collisions.md +30 -0
- data/demo/core/array/commonality.md +31 -0
- data/demo/core/array/conjoin.md +47 -0
- data/demo/core/array/contains.md +9 -0
- data/demo/core/array/delete_unless.md +13 -0
- data/demo/core/array/delete_values.md +10 -0
- data/demo/core/array/delete_values_at.md +15 -0
- data/demo/core/array/divide.md +14 -0
- data/demo/core/array/duplicates.md +14 -0
- data/demo/core/array/each_overlap.md +12 -0
- data/demo/core/array/each_pair.md +13 -0
- data/demo/core/array/each_value.md +12 -0
- data/demo/core/array/entropy.md +13 -0
- data/demo/core/array/extract_options.md +13 -0
- data/demo/core/array/first.md +11 -0
- data/demo/core/array/from.md +11 -0
- data/demo/core/array/ideal_entropy.md +11 -0
- data/demo/core/array/intersection.md +11 -0
- data/demo/core/array/last.md +11 -0
- data/demo/core/array/median.md +23 -0
- data/demo/core/array/merge.md +15 -0
- data/demo/core/array/missing.md +10 -0
- data/demo/core/array/mode.md +9 -0
- data/demo/core/array/nonuniq.md +16 -0
- data/demo/core/array/not_empty.md +8 -0
- data/demo/core/array/occur.md +18 -0
- data/demo/core/array/occurrence.md +13 -0
- data/demo/core/array/only.md +9 -0
- data/demo/core/array/op_pow.md +10 -0
- data/demo/core/array/pad.md +28 -0
- data/demo/core/array/peek.md +10 -0
- data/demo/core/array/poke.md +15 -0
- data/demo/core/array/probability +8 -0
- data/demo/core/array/pull.md +10 -0
- data/demo/core/array/recurse.md +10 -0
- data/demo/core/array/recursively.md +20 -0
- data/demo/core/array/reject_values.md +10 -0
- data/demo/core/array/splice.md +14 -0
- data/demo/core/array/split.md +13 -0
- data/demo/core/array/squeeze.md +14 -0
- data/demo/core/array/step.md +16 -0
- data/demo/core/array/store.md +9 -0
- data/demo/core/array/thru.md +12 -0
- data/demo/core/array/to_h.md +11 -0
- data/demo/core/array/traverse.md +20 -0
- data/demo/core/array/uniq_by.md +16 -0
- data/demo/core/array/unique_permutation.md +14 -0
- data/demo/core/array/zip.md +8 -0
- data/demo/core/binding/caller.md +57 -0
- data/demo/core/binding/defined.md +10 -0
- data/demo/core/binding/opvars.md +16 -0
- data/demo/core/binding/self.md +6 -0
- data/demo/core/class/descendants.md +13 -0
- data/demo/core/class/to_proc.md +11 -0
- data/demo/core/comparable/at_least.md +11 -0
- data/demo/core/comparable/at_most.md +11 -0
- data/demo/core/comparable/bound.md +13 -0
- data/demo/core/comparable/cap.md +11 -0
- data/demo/core/comparable/clip.md +29 -0
- data/demo/core/comparable/cmp.md +18 -0
- data/demo/core/comparable/op_get.md +32 -0
- data/demo/core/dir/ascend.md +24 -0
- data/demo/core/dir/descend.md +16 -0
- data/demo/core/dir/multiglob.md +41 -0
- data/demo/core/dir/parent.md +6 -0
- data/demo/core/dir/recurse.md +41 -0
- data/demo/core/exception/detail.md +19 -0
- data/demo/core/{facets.rdoc → facets.md} +1 -1
- data/demo/core/filetest/root.md +13 -0
- data/demo/core/hash/recursively.md +21 -0
- data/demo/core/indexable.md +95 -0
- data/demo/core/integer/bitmask.md +46 -0
- data/demo/core/integer/{factorial.rdoc → factorial.md} +1 -1
- data/demo/core/integer/{length.rdoc → length.md} +1 -1
- data/demo/core/integer/{multiple.rdoc → multiple.md} +3 -1
- data/demo/core/integer/of.md +11 -0
- data/demo/core/integer/{ordinal.rdoc → ordinal.md} +3 -1
- data/demo/core/integer/{of.rdoc → times_collect.md} +2 -7
- data/demo/core/matchdata/match.md +7 -0
- data/demo/core/matchdata/matchset.md +7 -0
- data/demo/core/matchdata/matchtree.md +10 -0
- data/demo/core/module/cattr.md +43 -0
- data/demo/core/module/class_extend.md +64 -0
- data/demo/core/module/{class_inheritor.rdoc → class_inheritor.md} +2 -2
- data/demo/core/module/{copy_inheritor.rdoc → copy_inheritor.md} +4 -4
- data/demo/core/module/include_as.md +31 -0
- data/demo/core/module/method_space.md +24 -0
- data/demo/core/string/acronym.md +9 -0
- data/demo/core/string/{align.rdoc → align.md} +10 -10
- data/demo/core/string/ascii_only.md +37 -0
- data/demo/core/string/{bracket.rdoc → bracket.md} +10 -10
- data/demo/core/string/camelcase.md +47 -0
- data/demo/core/string/{capitalized.rdoc → capitalized.md} +9 -9
- data/demo/core/string/characters.md +11 -0
- data/demo/core/string/{cleanlines.rdoc → cleanlines.md} +3 -3
- data/demo/core/string/cleave.md +49 -0
- data/demo/core/string/compress_lines.md +22 -0
- data/demo/core/string/crypt.md +15 -0
- data/demo/core/string/divide.md +9 -0
- data/demo/core/string/each_word.md +11 -0
- data/demo/core/string/edit_distance.md +15 -0
- data/demo/core/string/exclude.md +15 -0
- data/demo/core/string/expand_tabs.md +69 -0
- data/demo/core/string/fold.md +14 -0
- data/demo/core/string/indent.md +65 -0
- data/demo/core/string/index_all.md +14 -0
- data/demo/core/string/interpolate.md +8 -0
- data/demo/core/string/lchomp.md +14 -0
- data/demo/core/string/line_wrap.md +7 -0
- data/demo/core/string/lowercase.md +12 -0
- data/demo/core/string/methodize.md +22 -0
- data/demo/core/string/modulize.md +22 -0
- data/demo/core/string/mscan.md +10 -0
- data/demo/core/string/natcmp.md +10 -0
- data/demo/core/string/nchar.md +9 -0
- data/demo/core/string/{newlines.rdoc → newlines.md} +3 -3
- data/demo/core/string/number.md +27 -0
- data/demo/core/string/op_div.md +10 -0
- data/demo/core/string/op_sub.md +7 -0
- data/demo/core/string/pathize.md +22 -0
- data/demo/core/string/quote.md +20 -0
- data/demo/core/string/random.md +25 -0
- data/demo/core/string/range.md +19 -0
- data/demo/core/string/remove.md +33 -0
- data/demo/core/string/rewrite.md +9 -0
- data/demo/core/string/shatter.md +9 -0
- data/demo/core/string/similarity.md +12 -0
- data/demo/core/string/snakecase.md +14 -0
- data/demo/core/string/splice.md +28 -0
- data/demo/core/string/squish.md +27 -0
- data/demo/core/string/store.md +10 -0
- data/demo/core/string/subtract.md +8 -0
- data/demo/core/string/titlecase.md +8 -0
- data/demo/core/string/to_re.md +22 -0
- data/demo/core/string/{margin.rdoc → trim.md} +14 -14
- data/demo/core/string/unbracket.md +24 -0
- data/demo/core/string/underscore.md +17 -0
- data/demo/core/string/unfold.md +9 -0
- data/demo/core/string/unindent.md +65 -0
- data/demo/core/string/unquote.md +6 -0
- data/demo/core/string/uppercase.md +15 -0
- data/demo/core/string/variablize.md +7 -0
- data/demo/core/string/word_wrap.md +54 -0
- data/demo/core/string/words.md +13 -0
- data/demo/core/string/xor.md +8 -0
- data/lib/core/facets.yml +11 -7
- data/lib/core/facets/array.rb +1 -0
- data/lib/core/facets/array/average.rb +16 -0
- data/lib/core/facets/array/collapse.rb +4 -0
- data/lib/core/facets/array/delete_values_at.rb +1 -0
- data/lib/core/facets/array/divide.rb +7 -0
- data/lib/core/facets/array/duplicates.rb +2 -0
- data/lib/core/facets/array/each_pair.rb +1 -4
- data/lib/core/facets/array/first.rb +1 -0
- data/lib/core/facets/array/from.rb +11 -16
- data/lib/core/facets/array/intersection.rb +1 -1
- data/lib/core/facets/array/last.rb +1 -0
- data/lib/core/facets/array/mode.rb +2 -2
- data/lib/core/facets/array/occurrence.rb +4 -3
- data/lib/core/facets/array/op_pow.rb +0 -2
- data/lib/core/facets/array/probability.rb +1 -1
- data/lib/core/facets/array/recursively.rb +2 -2
- data/lib/core/facets/array/splice.rb +1 -1
- data/lib/core/facets/array/standard_deviation.rb +23 -0
- data/lib/core/facets/array/to_h.rb +0 -3
- data/lib/core/facets/array/uniq_by.rb +4 -0
- data/lib/core/facets/array/variance.rb +20 -0
- data/lib/core/facets/binding.rb +0 -1
- data/lib/core/facets/enumerable/cluster.rb +6 -4
- data/lib/core/facets/enumerable/hashify.rb +27 -31
- data/lib/core/facets/enumerable/sum.rb +12 -2
- data/lib/core/facets/file/atomic_open.rb +1 -1
- data/lib/core/facets/hash/except.rb +13 -1
- data/lib/core/facets/indexable.rb +1 -1
- data/lib/core/facets/kernel/ergo.rb +3 -3
- data/lib/core/facets/kernel/like.rb +1 -1
- data/lib/core/facets/matchdata/matchtree.rb +2 -0
- data/lib/core/facets/numeric/delimit.rb +20 -0
- data/lib/core/facets/range/nudge.rb +29 -0
- data/lib/core/facets/string.rb +0 -2
- data/lib/core/facets/string/indent.rb +0 -8
- data/lib/core/facets/string/margin.rb +0 -4
- data/lib/core/facets/string/random.rb +13 -3
- data/lib/core/facets/string/similarity.rb +7 -6
- data/lib/standard/facets/enumargs.rb +5 -0
- data/lib/standard/facets/math/percentile.rb +1 -1
- data/lib/standard/facets/net/http.rb +33 -14
- data/lib/standard/facets/timer.rb +3 -3
- data/test/core/array/test_average.rb +16 -0
- data/test/core/array/test_before.rb +21 -0
- data/test/core/array/test_collapse.rb +10 -1
- data/test/core/array/test_delete_unless.rb +17 -0
- data/test/core/array/test_delete_values.rb +31 -0
- data/test/core/array/test_divide.rb +10 -0
- data/test/core/array/test_each_pair.rb +16 -0
- data/test/core/array/test_each_value.rb +16 -0
- data/test/core/array/test_from.rb +42 -0
- data/test/core/array/test_op_pow.rb +13 -0
- data/test/core/array/test_standard_deviation.rb +18 -0
- data/test/core/array/test_to_h.rb +14 -0
- data/test/core/array/test_uniq_by.rb +7 -0
- data/test/core/array/test_variance.rb +17 -0
- data/test/core/array/test_zip.rb +13 -0
- data/test/core/dir/test_each_child.rb +1 -1
- data/test/core/dir/test_multiglob.rb +1 -1
- data/test/core/enumerable/test_cluster.rb +36 -0
- data/test/core/enumerable/test_hashify.rb +113 -0
- data/test/core/hash/test_expect.rb +11 -1
- data/test/core/kernel/test_ergo.rb +7 -5
- data/test/core/{object/test_replace.rb → kernel/test_instance_replace.rb} +6 -28
- data/test/core/numeric/test_delimit.rb +68 -0
- data/test/core/numeric/{test_round.rb → test_round_to.rb} +27 -27
- data/test/core/range/test_nudge.rb +32 -0
- data/test/core/range/{test_to_r.rb → test_to_rng.rb} +3 -3
- data/test/core/string/test_acronym.rb +14 -0
- data/test/core/string/test_ascii_only.rb +21 -0
- data/test/core/string/test_compress_lines.rb +9 -0
- data/test/core/string/test_crypt.rb +17 -0
- data/test/core/string/test_index_all.rb +4 -0
- data/test/core/string/test_random.rb +25 -0
- data/test/core/string/test_remove.rb +14 -0
- data/test/core/string/test_similarity.rb +9 -1
- data/test/core/struct/test_replace.rb +18 -0
- data/test/standard/test_enumargs.rb +26 -10
- data/test/standard/test_timer.rb +1 -1
- metadata +634 -588
- data/CONTRIBUTE.md +0 -78
- data/demo/core/array/combination.rdoc +0 -19
- data/demo/core/array/delete.rdoc +0 -23
- data/demo/core/array/index.rdoc +0 -14
- data/demo/core/array/merge.rdoc +0 -15
- data/demo/core/array/only.rdoc +0 -9
- data/demo/core/array/pad.rdoc +0 -28
- data/demo/core/array/permutation.rdoc +0 -10
- data/demo/core/array/product.rdoc +0 -26
- data/demo/core/array/recursively.rdoc +0 -16
- data/demo/core/array/rotate.rdoc +0 -30
- data/demo/core/array/select.rdoc +0 -8
- data/demo/core/array/uniq_by.rdoc +0 -9
- data/demo/core/binding/caller.rdoc +0 -57
- data/demo/core/binding/defined.rdoc +0 -10
- data/demo/core/binding/eval.rdoc +0 -8
- data/demo/core/binding/local_variables.rdoc +0 -26
- data/demo/core/binding/opvars.rdoc +0 -16
- data/demo/core/binding/self.rdoc +0 -6
- data/demo/core/class/descendants.rdoc +0 -10
- data/demo/core/class/to_proc.rdoc +0 -8
- data/demo/core/comparable/cap.rdoc +0 -20
- data/demo/core/comparable/clip.rdoc +0 -37
- data/demo/core/comparable/cmp.rdoc +0 -18
- data/demo/core/comparable/op_get.rdoc +0 -29
- data/demo/core/dir/ascend.rdoc +0 -24
- data/demo/core/dir/descend.rdoc +0 -14
- data/demo/core/dir/multiglob.rdoc +0 -41
- data/demo/core/dir/parent.rdoc +0 -6
- data/demo/core/dir/recurse.rdoc +0 -41
- data/demo/core/exception/detail.rdoc +0 -12
- data/demo/core/filetest/root.rdoc +0 -6
- data/demo/core/hash/recursively.rdoc +0 -21
- data/demo/core/indexable.rdoc +0 -95
- data/demo/core/integer/bitmask.rdoc +0 -46
- data/demo/core/integer/even.rdoc +0 -12
- data/demo/core/integer/odd.rdoc +0 -12
- data/demo/core/matchdata/match.rdoc +0 -7
- data/demo/core/matchdata/matchset.rdoc +0 -15
- data/demo/core/module/cattr.rdoc +0 -43
- data/demo/core/module/class_extend.rdoc +0 -64
- data/demo/core/module/method_space.rdoc +0 -55
- data/demo/core/string/bytes.rdoc +0 -8
- data/demo/core/string/camelcase.rdoc +0 -47
- data/demo/core/string/characters.rdoc +0 -11
- data/demo/core/string/cleave.rdoc +0 -49
- data/demo/core/string/divide.rdoc +0 -9
- data/demo/core/string/each_char.rdoc +0 -9
- data/demo/core/string/each_word.rdoc +0 -9
- data/demo/core/string/end_with.rdoc +0 -6
- data/demo/core/string/expand_tabs.rdoc +0 -69
- data/demo/core/string/fold.rdoc +0 -14
- data/demo/core/string/indent.rdoc +0 -65
- data/demo/core/string/interpolate.rdoc +0 -7
- data/demo/core/string/lchomp.rdoc +0 -14
- data/demo/core/string/line_wrap.rdoc +0 -7
- data/demo/core/string/lines.rdoc +0 -8
- data/demo/core/string/methodize.rdoc +0 -22
- data/demo/core/string/modulize.rdoc +0 -22
- data/demo/core/string/mscan.rdoc +0 -10
- data/demo/core/string/natcmp.rdoc +0 -10
- data/demo/core/string/nchar.rdoc +0 -9
- data/demo/core/string/op_sub.rdoc +0 -7
- data/demo/core/string/pathize.rdoc +0 -22
- data/demo/core/string/quote.rdoc +0 -20
- data/demo/core/string/range.rdoc +0 -19
- data/demo/core/string/rewrite.rdoc +0 -9
- data/demo/core/string/shatter.rdoc +0 -9
- data/demo/core/string/snakecase.rdoc +0 -10
- data/demo/core/string/splice.rdoc +0 -28
- data/demo/core/string/start_with.rdoc +0 -7
- data/demo/core/string/subtract.rdoc +0 -8
- data/demo/core/string/tab.rdoc +0 -16
- data/demo/core/string/tabto.rdoc +0 -29
- data/demo/core/string/titlecase.rdoc +0 -8
- data/demo/core/string/to_re.rdoc +0 -22
- data/demo/core/string/unfold.rdoc +0 -9
- data/demo/core/string/unindent.rdoc +0 -65
- data/demo/core/string/unquote.rdoc +0 -6
- data/demo/core/string/variablize.rdoc +0 -7
- data/demo/core/string/word_wrap.rdoc +0 -54
- data/demo/core/string/words.rdoc +0 -13
- data/demo/core/string/xor.rdoc +0 -8
- data/lib/core/facets/binding/local_variables.rb +0 -16
- data/lib/core/facets/string/tab.rb +0 -2
- data/lib/core/facets/string/tabto.rb +0 -2
- data/test/core/array/test_after.rb +0 -27
- data/test/core/array/test_combination.rb +0 -25
- data/test/core/array/test_index.rb +0 -20
- data/test/core/array/test_permutation.rb +0 -20
- data/test/core/array/test_product.rb +0 -64
- data/test/core/array/test_rotate.rb +0 -38
- data/test/core/array/test_select.rb +0 -16
- data/test/core/binding/test_eval.rb +0 -15
- data/test/core/binding/test_local_variables.rb +0 -36
- data/test/core/enumerable/test_cluster_by.rb +0 -30
- data/test/core/enumerable/test_count.rb +0 -32
- data/test/core/enumerable/test_each_with_object.rb +0 -18
- data/test/core/enumerable/test_group_by.rb +0 -36
- data/test/core/enumerable/test_none.rb +0 -29
- data/test/core/enumerable/test_one.rb +0 -34
- data/test/core/enumerable/test_take.rb +0 -15
- data/test/core/hash/test_select.rb +0 -44
- data/test/core/hash/test_url_params.rb +0 -26
- data/test/core/integer/test_even.rb +0 -24
- data/test/core/integer/test_odd.rb +0 -24
- data/test/core/kernel/test_require_relative.rb +0 -12
- data/test/core/nilclass/test_to_f.rb +0 -13
- data/test/core/proc/test_curry.rb +0 -38
- data/test/core/string/test_bytes.rb +0 -13
- data/test/core/string/test_each_char.rb +0 -17
- data/test/core/string/test_end_with.rb +0 -24
- data/test/core/string/test_lines.rb +0 -15
- data/test/core/string/test_start_with.rb +0 -24
- data/test/core/string/test_tab.rb +0 -16
- data/test/core/symbol/test_to_proc.rb +0 -35
- data/test/core/to_hash_tc.rb +0 -210
- data/test/core/unboundmethod/test_name.rb +0 -19
@@ -0,0 +1,46 @@
|
|
1
|
+
## Integer#bit
|
2
|
+
|
3
|
+
require 'facets/integer/bitmask'
|
4
|
+
|
5
|
+
0.bit(0).assert == 1
|
6
|
+
0.bit(1).assert == 2
|
7
|
+
0.bit(2).assert == 4
|
8
|
+
0.bit(3).assert == 8
|
9
|
+
|
10
|
+
Negate
|
11
|
+
|
12
|
+
1.bit(~0).assert == 0
|
13
|
+
2.bit(~1).assert == 0
|
14
|
+
4.bit(~2).assert == 0
|
15
|
+
8.bit(~3).assert == 0
|
16
|
+
|
17
|
+
## Integer#bit?
|
18
|
+
|
19
|
+
a = 8
|
20
|
+
assert(! a.bit?(0))
|
21
|
+
assert(! a.bit?(1))
|
22
|
+
assert(! a.bit?(2))
|
23
|
+
assert( a.bit?(3))
|
24
|
+
assert(! a.bit?(4))
|
25
|
+
assert(! a.bit?(5))
|
26
|
+
|
27
|
+
## Integer#bit_clear
|
28
|
+
|
29
|
+
1.bit_clear(0).assert == 0
|
30
|
+
2.bit_clear(1).assert == 0
|
31
|
+
4.bit_clear(2).assert == 0
|
32
|
+
8.bit_clear(3).assert == 0
|
33
|
+
|
34
|
+
## Integer#bitmask
|
35
|
+
|
36
|
+
a = 1
|
37
|
+
m = Bit(4)
|
38
|
+
a = a.bitmask(m)
|
39
|
+
a.assert == 17
|
40
|
+
assert( a.bitmask?(m) )
|
41
|
+
|
42
|
+
## Kernel#Bit
|
43
|
+
|
44
|
+
n = Bit(4)
|
45
|
+
n.assert == 16
|
46
|
+
|
@@ -1,14 +1,9 @@
|
|
1
|
-
|
1
|
+
## Integer#times_collect
|
2
2
|
|
3
3
|
require 'facets/integer/of'
|
4
4
|
|
5
|
-
a = 4
|
6
|
-
b = a.of{ |i| i*2 }
|
7
|
-
b.assert == [0,2,4,6]
|
8
|
-
|
9
|
-
== Integer#times_collect
|
10
|
-
|
11
5
|
a = 4
|
12
6
|
b = a.times_collect{ |i| i*2 }
|
13
7
|
b.assert == [0,2,4,6]
|
14
8
|
|
9
|
+
See `Integer#of` which is an alias.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
## MatchData#matchtree
|
2
|
+
|
3
|
+
require 'facets/matchdata/matchtree'
|
4
|
+
|
5
|
+
md = /(bb)(cc(dd))(ee)/.match "XXaabbccddeeffXX"
|
6
|
+
md.matchtree.assert == [["bb"], ["cc", ["dd"]], ["ee"]]
|
7
|
+
|
8
|
+
md = /(bb)c(c(dd))(ee)/.match "XXaabbccddeeffXX"
|
9
|
+
md.matchtree.assert == [["bb"], "c", ["c", ["dd"]], ["ee"]]
|
10
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
## Class#cattr
|
2
|
+
|
3
|
+
require 'facets/module/cattr'
|
4
|
+
|
5
|
+
class CAttrMockObject
|
6
|
+
def initialize
|
7
|
+
@@a = 10
|
8
|
+
end
|
9
|
+
def b ; @@b ; end
|
10
|
+
end
|
11
|
+
|
12
|
+
Exception.refute.raised? do
|
13
|
+
CAttrMockObject.class_eval{ cattr :a }
|
14
|
+
end
|
15
|
+
t = CAttrMockObject.new
|
16
|
+
t.a.assert == 10
|
17
|
+
|
18
|
+
## Class#cattr_reader
|
19
|
+
|
20
|
+
Exception.refute.raised? do
|
21
|
+
CAttrMockObject.class_eval { cattr_reader :a }
|
22
|
+
end
|
23
|
+
t = CAttrMockObject.new
|
24
|
+
t.a.assert == 10
|
25
|
+
|
26
|
+
## Class#cattr_writer
|
27
|
+
|
28
|
+
Exception.refute.raised? do
|
29
|
+
CAttrMockObject.class_eval { cattr_writer :b }
|
30
|
+
end
|
31
|
+
t = CAttrMockObject.new
|
32
|
+
t.b = 5
|
33
|
+
t.b.assert == 5
|
34
|
+
|
35
|
+
## Class#cattr_accessor
|
36
|
+
|
37
|
+
Exception.refute.raised? do
|
38
|
+
CAttrMockObject.class_eval { cattr_accessor :c }
|
39
|
+
end
|
40
|
+
t = CAttrMockObject.new
|
41
|
+
t.c = 50
|
42
|
+
t.c.assert == 50
|
43
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
## Module#class_extend
|
2
|
+
|
3
|
+
require 'facets/module/class_extend'
|
4
|
+
|
5
|
+
Module using class_extend
|
6
|
+
|
7
|
+
mix = Module.new do
|
8
|
+
def i ; end
|
9
|
+
class_extend do
|
10
|
+
def n ; 42 ; end
|
11
|
+
def s ; self ; end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Extends module
|
16
|
+
|
17
|
+
mix.n.assert == 42
|
18
|
+
mix.s.assert == mix
|
19
|
+
|
20
|
+
Has expected methods
|
21
|
+
|
22
|
+
mix.instance_methods.map{ |m| m.to_s }.assert == ['i']
|
23
|
+
|
24
|
+
transfers class methods to including class
|
25
|
+
|
26
|
+
mod = Module.new do
|
27
|
+
include mix
|
28
|
+
end
|
29
|
+
mod.n.assert == 42
|
30
|
+
mod.s.assert == mod
|
31
|
+
|
32
|
+
Doesn't overwrite instance methods
|
33
|
+
|
34
|
+
c = Class.new do
|
35
|
+
include mix
|
36
|
+
def n ; 11 ; end
|
37
|
+
end
|
38
|
+
c.new.n.assert == 11
|
39
|
+
|
40
|
+
Is overridable via including module
|
41
|
+
|
42
|
+
mod = Module.new do
|
43
|
+
include mix
|
44
|
+
class_extend do
|
45
|
+
def n ; super + 1 ; end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
mod.n.assert == 43 # notice the difference!
|
49
|
+
mod.s.assert == mod
|
50
|
+
|
51
|
+
Transfers class methods thru multiple levels of include
|
52
|
+
|
53
|
+
alt = Module.new do
|
54
|
+
include mix
|
55
|
+
class_extend do
|
56
|
+
def n ; super + 1 ; end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
mod = Module.new do
|
60
|
+
include alt
|
61
|
+
end
|
62
|
+
mod.n.assert == 43
|
63
|
+
mod.s.assert == mod
|
64
|
+
|
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
## Module#copy_inheritor
|
2
2
|
|
3
|
-
|
3
|
+
require 'facets/module/copy_inheritor'
|
4
4
|
|
5
|
-
We see copy_inheritor
|
5
|
+
We see `#copy_inheritor` in action.
|
6
6
|
|
7
7
|
m = Module.new do
|
8
8
|
copy_inheritor :koko, []
|
@@ -22,7 +22,7 @@ We see copy_inheritor
|
|
22
22
|
koko << 4
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
And the result.
|
26
26
|
|
27
27
|
m.koko.assert == [1]
|
28
28
|
c1.koko.assert == [1,2,3]
|
@@ -0,0 +1,31 @@
|
|
1
|
+
## Module#include_as
|
2
|
+
|
3
|
+
require 'facets/module/include_as'
|
4
|
+
|
5
|
+
Module#include_as utilizes #method_space to allow modules to be included
|
6
|
+
within a separated namespace.
|
7
|
+
|
8
|
+
module T
|
9
|
+
def t ; "Tt" ; end
|
10
|
+
def r ; "Tr" ; end
|
11
|
+
def q ; super ; end
|
12
|
+
end
|
13
|
+
|
14
|
+
class N
|
15
|
+
def q ; "Nq" ; end
|
16
|
+
end
|
17
|
+
|
18
|
+
class X < N
|
19
|
+
include_as :test => T
|
20
|
+
|
21
|
+
def n ; test.inspect ; end
|
22
|
+
def m ; test.t ; end
|
23
|
+
def o ; test.r ; end
|
24
|
+
end
|
25
|
+
|
26
|
+
x = X.new
|
27
|
+
|
28
|
+
x.m.assert == "Tt"
|
29
|
+
x.o.assert == "Tr"
|
30
|
+
x.q.assert == "Nq"
|
31
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
## Module#method_space
|
2
|
+
|
3
|
+
require 'facets/module/method_space'
|
4
|
+
|
5
|
+
class A
|
6
|
+
attr_writer :x
|
7
|
+
method_space :inside do
|
8
|
+
def x; @x; end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
a = A.new
|
13
|
+
a.x = 10
|
14
|
+
|
15
|
+
We can see that the `inside` method space has access to the instance space.
|
16
|
+
|
17
|
+
a.inside.x #=> 10
|
18
|
+
|
19
|
+
But there is no reader in the instance space.
|
20
|
+
|
21
|
+
expect NoMethodError do
|
22
|
+
a.x
|
23
|
+
end
|
24
|
+
|
@@ -1,34 +1,34 @@
|
|
1
|
-
|
1
|
+
## String#align
|
2
2
|
|
3
|
-
|
3
|
+
require 'facets/string/align'
|
4
4
|
|
5
5
|
Align a string to a given position. This method simply delegates
|
6
6
|
to the other three more specific align methods.
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
"xxx".align(:right, 9).assert == " xxx"
|
9
|
+
"xxx".align(:left, 9).assert == "xxx "
|
10
10
|
|
11
|
-
|
11
|
+
## String#align_right
|
12
12
|
|
13
13
|
Align a string to the right. The default alignment separation is
|
14
14
|
a newline ("\n"). This can be changed as can be the padding string
|
15
15
|
which defaults to a single space (' ').
|
16
16
|
|
17
|
-
|
17
|
+
"xxx".align_right(9).assert == " xxx"
|
18
18
|
|
19
|
-
|
19
|
+
## String#align_left
|
20
20
|
|
21
21
|
Align a string to the left. The default alignment separation is a
|
22
22
|
newline ("\n"). This can be changed as can be the padding string
|
23
23
|
which defaults to a single space (' ').
|
24
24
|
|
25
|
-
|
25
|
+
"xxx".align_left(9).assert == "xxx "
|
26
26
|
|
27
|
-
|
27
|
+
## String#align_center
|
28
28
|
|
29
29
|
Centers each line of a string. The default alignment separation is
|
30
30
|
a new line ("\n"). This can be changed as can be the padding string
|
31
31
|
which defaults to a single space (' ').
|
32
32
|
|
33
|
-
|
33
|
+
"xxx".align_center(9).assert == " xxx "
|
34
34
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
## String#ascii_only
|
2
|
+
|
3
|
+
require 'facets/string/ascii_only'
|
4
|
+
|
5
|
+
Return a new string with non-ASCII characters removed.
|
6
|
+
|
7
|
+
'abc'.ascii_only.assert == 'abc'
|
8
|
+
'中文123'.ascii_only.assert == '123'
|
9
|
+
|
10
|
+
Return a new string with non-ASCII characters replaced.
|
11
|
+
|
12
|
+
'中文123'.ascii_only('!').assert == '!!123'
|
13
|
+
|
14
|
+
## String#ascii_only!
|
15
|
+
|
16
|
+
Modifiy string with non-ASCII chracters removed.
|
17
|
+
|
18
|
+
s = 'abc'
|
19
|
+
s.ascii_only!
|
20
|
+
s.assert == 'abc'
|
21
|
+
|
22
|
+
s = '中文123'
|
23
|
+
s.ascii_only!
|
24
|
+
s.assert == '123'
|
25
|
+
|
26
|
+
|
27
|
+
Modifiy string with non-ASCII chracters replaced.
|
28
|
+
|
29
|
+
s = 'abc'
|
30
|
+
s.ascii_only!('!')
|
31
|
+
s.assert == 'abc'
|
32
|
+
|
33
|
+
s = '中文123'
|
34
|
+
s.ascii_only!('!')
|
35
|
+
s.assert == '!!123'
|
36
|
+
|
37
|
+
|
@@ -1,16 +1,16 @@
|
|
1
|
-
|
1
|
+
## String#bracket
|
2
2
|
|
3
|
-
|
3
|
+
require 'facets/string/bracket'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
'X'.bracket('#').assert == '#X#'
|
6
|
+
'X'.bracket('x','!').assert == 'xX!'
|
7
|
+
'X'.bracket('{','}').assert == '{X}'
|
8
|
+
'X'.bracket('<').assert == '<X>'
|
9
|
+
'X'.bracket('(').assert == '(X)'
|
10
|
+
'X'.bracket('[').assert == '[X]'
|
11
|
+
'X'.bracket('{').assert == '{X}'
|
12
12
|
|
13
|
-
|
13
|
+
## String#bracket!
|
14
14
|
|
15
15
|
a = 'X' ; a.bracket!('#')
|
16
16
|
a.assert == '#X#'
|