facets 2.1.3 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +14 -12
- data/CHANGES +45 -2
- data/NOTES +9 -7
- data/lib/core/facets/1stclassmethod.rb +15 -11
- data/lib/core/facets/array.rb +0 -1
- data/lib/core/facets/array/conjoin.rb +40 -8
- data/lib/core/facets/array/delete.rb +8 -2
- data/lib/core/facets/array/indexable.rb +30 -3
- data/lib/core/facets/array/merge.rb +11 -0
- data/lib/core/facets/array/only.rb +3 -3
- data/lib/core/facets/array/pad.rb +4 -46
- data/lib/core/facets/array/rotate.rb +4 -4
- data/lib/core/facets/array/select.rb +2 -0
- data/lib/core/facets/array/splice.rb +16 -2
- data/lib/core/facets/array/stackable.rb +6 -40
- data/lib/core/facets/binding.rb +3 -0
- data/lib/core/facets/binding/cflow.rb +10 -64
- data/lib/core/facets/binding/defined.rb +10 -0
- data/lib/core/facets/binding/eval.rb +10 -76
- data/lib/core/facets/binding/here.rb +9 -0
- data/lib/core/facets/binding/self.rb +10 -0
- data/lib/core/facets/binding/vars.rb +0 -45
- data/lib/core/facets/boolean.rb +31 -103
- data/lib/core/facets/class/descendents.rb +17 -44
- data/lib/core/facets/comparable/bound.rb +8 -70
- data/lib/core/facets/comparable/cmp.rb +12 -92
- data/lib/core/facets/conversion.rb +122 -321
- data/lib/core/facets/dir/multiglob.rb +0 -13
- data/lib/core/facets/dir/traverse.rb +61 -111
- data/lib/core/facets/enumerable.rb +4 -2
- data/lib/core/facets/enumerable/cartesian.rb +36 -85
- data/lib/core/facets/enumerable/collect.rb +64 -152
- data/lib/core/facets/enumerable/combination.rb +40 -42
- data/lib/core/facets/enumerable/count.rb +99 -174
- data/lib/core/facets/enumerable/each.rb +86 -0
- data/lib/core/facets/enumerable/mash.rb +58 -0
- data/lib/core/facets/enumerable/permutation.rb +39 -44
- data/lib/core/facets/enumerable/probability.rb +16 -90
- data/lib/core/facets/enumerable/split.rb +113 -0
- data/lib/core/facets/exception/detail.rb +1 -2
- data/lib/core/facets/facets.rb +3 -2
- data/lib/core/facets/file/read.rb +4 -59
- data/lib/core/facets/file/topath.rb +8 -96
- data/lib/core/facets/file/write.rb +21 -49
- data/lib/core/facets/filetest/root.rb +4 -3
- data/lib/core/facets/functor.rb +5 -43
- data/lib/core/facets/hash/at.rb +7 -37
- data/lib/core/facets/hash/delete.rb +9 -58
- data/lib/core/facets/hash/has_keys.rb +4 -43
- data/lib/core/facets/hash/insert.rb +5 -38
- data/lib/core/facets/hash/inverse.rb +2 -41
- data/lib/core/facets/hash/iterate.rb +4 -45
- data/lib/core/facets/hash/keyize.rb +24 -92
- data/lib/core/facets/hash/merge.rb +4 -38
- data/lib/core/facets/hash/new.rb +5 -38
- data/lib/core/facets/hash/op.rb +20 -66
- data/lib/core/facets/hash/rekey.rb +9 -87
- data/lib/core/facets/hash/select.rb +1 -1
- data/lib/core/facets/hash/slice.rb +42 -0
- data/lib/core/facets/hash/traverse.rb +6 -46
- data/lib/core/facets/hash/update.rb +27 -67
- data/lib/core/facets/hash/weave.rb +22 -42
- data/lib/core/facets/indexable.rb +42 -14
- data/lib/core/facets/integer/bitmask.rb +69 -106
- data/lib/core/facets/integer/factorial.rb +1 -44
- data/lib/core/facets/integer/multiples.rb +27 -22
- data/lib/core/facets/integer/of.rb +1 -33
- data/lib/core/facets/kernel.rb +4 -2
- data/lib/core/facets/kernel/ask.rb +15 -3
- data/lib/core/facets/kernel/callstack.rb +38 -69
- data/lib/core/facets/kernel/constant.rb +2 -38
- data/lib/core/facets/kernel/deepcopy.rb +3 -55
- data/lib/core/facets/kernel/dir.rb +2 -0
- data/lib/core/facets/kernel/ergo.rb +2 -2
- data/lib/core/facets/kernel/instance.rb +51 -120
- data/lib/core/facets/kernel/metaid.rb +35 -73
- data/lib/core/facets/kernel/object.rb +14 -39
- data/lib/core/facets/kernel/op_esc.rb +24 -2
- data/lib/core/facets/kernel/populate.rb +6 -69
- data/lib/core/facets/kernel/report.rb +28 -33
- data/lib/core/facets/kernel/require.rb +7 -21
- data/lib/core/facets/kernel/respond.rb +11 -1
- data/lib/core/facets/kernel/returning.rb +50 -0
- data/lib/core/facets/kernel/silence.rb +12 -24
- data/lib/core/facets/kernel/super.rb +12 -76
- data/lib/core/facets/kernel/tap.rb +25 -107
- data/lib/core/facets/kernel/val.rb +7 -46
- data/lib/core/facets/kernel/withattr.rb +6 -64
- data/lib/core/facets/matchdata/matchset.rb +8 -50
- data/lib/core/facets/module.rb +3 -1
- data/lib/core/facets/module/abstract.rb +9 -47
- data/lib/core/facets/module/alias.rb +11 -68
- data/lib/core/facets/module/attr.rb +36 -15
- data/lib/core/facets/module/cattr.rb +8 -76
- data/lib/core/facets/module/clone.rb +15 -66
- data/lib/core/facets/module/include.rb +54 -114
- data/lib/core/facets/module/methods.rb +15 -13
- data/lib/core/facets/module/modify.rb +20 -206
- data/lib/core/facets/module/name.rb +19 -83
- data/lib/core/facets/module/require.rb +48 -53
- data/lib/core/facets/module/traits.rb +74 -33
- data/lib/core/facets/nilclass/status.rb +25 -2
- data/lib/core/facets/numeric/round.rb +24 -89
- data/lib/core/facets/proc/bind.rb +16 -59
- data/lib/core/facets/proc/compose.rb +6 -40
- data/lib/core/facets/proc/fn.rb +2 -0
- data/lib/core/facets/range/combine.rb +15 -51
- data/lib/core/facets/range/overlap.rb +8 -64
- data/lib/core/facets/regexp/arity.rb +6 -41
- data/lib/core/facets/stackable.rb +43 -4
- data/lib/core/facets/string.rb +2 -0
- data/lib/core/facets/string/align.rb +45 -55
- data/lib/core/facets/string/blank.rb +2 -46
- data/lib/core/facets/string/bracket.rb +14 -87
- data/lib/core/facets/string/case.rb +45 -32
- data/lib/core/facets/string/crypt.rb +3 -40
- data/lib/core/facets/string/filter.rb +7 -49
- data/lib/core/facets/string/format.rb +24 -126
- data/lib/core/facets/string/indexable.rb +50 -133
- data/lib/core/facets/string/interpolate.rb +24 -59
- data/lib/core/facets/string/natcmp.rb +5 -39
- data/lib/core/facets/string/nchar.rb +37 -45
- data/lib/core/facets/string/op.rb +13 -0
- data/lib/core/facets/string/partitions.rb +38 -99
- data/lib/core/facets/string/range.rb +8 -49
- data/lib/core/facets/string/regesc.rb +9 -42
- data/lib/core/facets/string/scan.rb +6 -52
- data/lib/core/facets/string/splice.rb +8 -13
- data/lib/core/facets/string/tabs.rb +16 -153
- data/lib/core/facets/symbol.rb +3 -1
- data/lib/core/facets/symbol/chomp.rb +11 -29
- data/lib/core/facets/symbol/generate.rb +4 -43
- data/lib/core/facets/symbol/not.rb +13 -25
- data/lib/core/facets/symbol/shadow.rb +2 -40
- data/lib/core/facets/symbol/succ.rb +14 -13
- data/lib/core/facets/symbol/to_proc.rb +33 -28
- data/lib/core/facets/time.rb +1 -0
- data/lib/core/facets/time/change.rb +5 -38
- data/lib/core/facets/time/elapse.rb +2 -41
- data/lib/core/facets/time/stamp.rb +47 -0
- data/lib/core/facets/unboundmethod.rb +3 -0
- data/lib/core/facets/unboundmethod/arguments.rb +27 -4
- data/lib/core/facets/unboundmethod/name.rb +21 -7
- data/lib/methods/facets/enumerable/cluster_by.rb +1 -1
- data/lib/methods/facets/enumerable/collate.rb +1 -0
- data/lib/methods/facets/enumerable/divide.rb +1 -1
- data/lib/methods/facets/enumerable/each_by.rb +1 -1
- data/lib/methods/facets/enumerable/each_pair.rb +1 -1
- data/lib/methods/facets/enumerable/eachn.rb +1 -1
- data/lib/methods/facets/enumerable/graph.rb +1 -1
- data/lib/methods/facets/enumerable/group_by.rb +1 -1
- data/lib/methods/facets/enumerable/inject.rb +1 -0
- data/lib/methods/facets/enumerable/map_send.rb +1 -0
- data/lib/methods/facets/enumerable/modulate.rb +1 -0
- data/lib/methods/facets/enumerable/partition_by.rb +1 -1
- data/lib/methods/facets/hash/collate.rb +1 -1
- data/lib/methods/facets/hash/except.rb +1 -0
- data/lib/methods/facets/hash/graph.rb +1 -1
- data/lib/methods/facets/hash/mash.rb +1 -0
- data/lib/methods/facets/kernel/Bit.rb +1 -0
- data/lib/methods/facets/kernel/complete.rb +1 -1
- data/lib/methods/facets/kernel/here.rb +1 -1
- data/lib/methods/facets/kernel/non_nil.rb +1 -0
- data/lib/methods/facets/kernel/respond_with_value.rb +1 -0
- data/lib/methods/facets/kernel/with.rb +1 -1
- data/lib/methods/facets/module/class_def.rb +1 -0
- data/lib/methods/facets/string/camelcase.rb +1 -0
- data/lib/methods/facets/string/op_minus.rb +1 -0
- data/lib/methods/facets/string/snakecase.rb +1 -0
- data/lib/more/facets/attributes.rb +5 -5
- data/lib/more/facets/basicobject.rb +0 -62
- data/lib/{core/facets/continuation/create.rb → more/facets/continuation.rb} +4 -21
- data/lib/more/facets/duration.rb +534 -0
- data/lib/more/facets/lazy.rb +3 -3
- data/lib/more/facets/namespace.rb +23 -71
- data/lib/more/facets/rbsystem.rb +42 -8
- data/lib/more/facets/stylize.rb +6 -3
- data/lib/more/facets/thread.rb +55 -0
- data/meta/MANIFEST +49 -18
- data/meta/ROLLRC +1 -1
- data/meta/project.yaml +2 -2
- data/task/install +1 -1
- data/task/test/general +8 -2
- data/test/unit/array/test_pad.rb +30 -45
- data/test/unit/array/test_stackable.rb +14 -28
- data/test/unit/binding/test_cflow.rb +34 -49
- data/test/unit/binding/test_defined.rb +17 -0
- data/test/unit/binding/test_eval.rb +11 -39
- data/test/unit/binding/test_here.rb +17 -0
- data/test/unit/binding/test_self.rb +17 -0
- data/test/unit/binding/test_vars.rb +22 -37
- data/test/unit/class/test_descendents.rb +15 -30
- data/test/unit/class/test_initializer.rb +1 -8
- data/test/unit/comparable/test_bound.rb +38 -53
- data/test/unit/comparable/test_cmp.rb +45 -60
- data/test/unit/dir/test_traverse.rb +56 -0
- data/test/unit/enumerable/test_cartesian.rb +34 -47
- data/test/unit/enumerable/test_collect.rb +16 -125
- data/test/unit/enumerable/test_combination.rb +1 -8
- data/test/unit/enumerable/test_count.rb +51 -66
- data/test/unit/enumerable/test_each.rb +77 -0
- data/test/unit/enumerable/test_mash.rb +51 -0
- data/test/unit/enumerable/test_permutation.rb +1 -7
- data/test/unit/enumerable/test_probability.rb +42 -55
- data/test/unit/enumerable/test_split.rb +52 -0
- data/test/unit/exception/test_detail.rb +19 -0
- data/test/unit/file/test_read.rb +34 -0
- data/test/unit/file/test_topath.rb +17 -25
- data/test/unit/file/test_write.rb +6 -12
- data/test/unit/filetest/test_root.rb +14 -0
- data/test/unit/hash/test_at.rb +9 -21
- data/test/unit/hash/test_delete.rb +22 -37
- data/test/unit/hash/test_has_keys.rb +13 -28
- data/test/unit/hash/test_insert.rb +9 -23
- data/test/unit/hash/test_inverse.rb +11 -26
- data/test/unit/hash/test_iterate.rb +16 -31
- data/test/unit/hash/test_keyize.rb +40 -55
- data/test/unit/hash/test_merge.rb +10 -25
- data/test/unit/hash/test_new.rb +9 -24
- data/test/unit/hash/test_op.rb +1 -7
- data/test/unit/hash/test_rekey.rb +47 -62
- data/test/unit/hash/test_traverse.rb +17 -32
- data/test/unit/hash/test_update.rb +30 -45
- data/test/unit/hash/test_weave.rb +10 -23
- data/test/unit/integer/test_bitmask.rb +48 -44
- data/test/unit/integer/test_factorial.rb +11 -26
- data/test/unit/integer/test_multiples.rb +1 -5
- data/test/unit/integer/test_of.rb +14 -29
- data/test/unit/kernel/test_callstack.rb +13 -28
- data/test/unit/kernel/test_constant.rb +14 -28
- data/test/unit/kernel/test_deepcopy.rb +20 -35
- data/test/unit/kernel/test_instance.rb +46 -61
- data/test/unit/kernel/test_metaid.rb +42 -57
- data/test/unit/kernel/test_object.rb +14 -29
- data/test/unit/kernel/test_populate.rb +38 -53
- data/test/unit/kernel/test_report.rb +1 -7
- data/test/unit/kernel/test_returning.rb +16 -0
- data/test/unit/kernel/test_silence.rb +8 -23
- data/test/unit/kernel/test_super.rb +41 -56
- data/test/unit/kernel/test_tap.rb +15 -39
- data/test/unit/kernel/test_val.rb +7 -20
- data/test/unit/kernel/test_withattr.rb +29 -44
- data/test/unit/matchdata/test_matchset.rb +20 -35
- data/test/unit/module/test_abstract.rb +15 -30
- data/test/unit/module/test_alias.rb +32 -45
- data/test/unit/module/test_cattr.rb +39 -54
- data/test/unit/module/test_clone.rb +31 -43
- data/test/unit/module/test_include.rb +1 -35
- data/test/unit/module/test_modify.rb +102 -114
- data/test/unit/module/test_name.rb +1 -7
- data/test/unit/numeric/test_round.rb +46 -61
- data/test/unit/proc/test_bind.rb +29 -44
- data/test/unit/proc/test_compose.rb +20 -35
- data/test/unit/range/test_combine.rb +14 -29
- data/test/unit/range/test_overlap.rb +34 -51
- data/test/unit/regexp/test_arity.rb +14 -29
- data/test/unit/string/test_align.rb +13 -27
- data/test/unit/string/test_blank.rb +12 -27
- data/test/unit/string/test_bracket.rb +52 -67
- data/test/unit/string/test_case.rb +19 -38
- data/test/unit/string/test_crypt.rb +10 -25
- data/test/unit/string/test_filter.rb +1 -7
- data/test/unit/string/test_format.rb +2 -7
- data/test/unit/string/test_indexable.rb +54 -69
- data/test/unit/string/test_interpolate.rb +8 -21
- data/test/unit/string/test_natcmp.rb +11 -26
- data/test/unit/string/test_nchar.rb +1 -14
- data/test/unit/string/test_op.rb +14 -0
- data/test/unit/string/test_partitions.rb +39 -54
- data/test/unit/string/test_range.rb +17 -32
- data/test/unit/string/test_regesc.rb +1 -7
- data/test/unit/string/test_scan.rb +23 -38
- data/test/unit/string/test_stackable.rb +79 -98
- data/test/unit/string/test_tabs.rb +1 -7
- data/test/unit/symbol/test_chomp.rb +10 -21
- data/test/unit/symbol/test_generate.rb +7 -22
- data/test/unit/symbol/test_not.rb +10 -25
- data/test/unit/symbol/test_shadow.rb +8 -23
- data/test/unit/symbol/test_succ.rb +1 -7
- data/test/unit/symbol/test_to_proc.rb +1 -7
- data/test/unit/test_attributes.rb +1 -1
- data/test/unit/test_continuation.rb +13 -0
- data/test/unit/test_conversion.rb +1 -14
- data/test/unit/test_namespace.rb +30 -3
- data/test/unit/test_thread.rb +23 -0
- data/test/unit/time/test_change.rb +11 -26
- data/test/unit/time/test_elapse.rb +10 -25
- data/test/unit/time/test_stamp.rb +28 -0
- metadata +65 -25
- data/lib/core/facets/array/unzip.rb +0 -14
- data/lib/core/facets/continuation.rb +0 -1
- data/lib/core/facets/enumerable/collate.rb +0 -104
- data/lib/core/facets/kernel/require_esc.rb +0 -44
- data/lib/more/facets/mapsend.rb +0 -98
- data/lib/more/facets/pp_s.rb +0 -30
- data/log/history.rd +0 -38
- data/log/todo.rd +0 -4
- data/task/special/quickopts +0 -15
- data/test/unit/continuation/test_create.rb +0 -28
- data/test/unit/enumerable/test_collate.rb +0 -51
- data/test/unit/kernel/test_require_esc.rb +0 -29
- data/test/unit/test_mapsend.rb +0 -18
- data/test/unit/test_pp_s.rb +0 -17
@@ -1,21 +1,17 @@
|
|
1
|
-
# TITLE:
|
1
|
+
# = TITLE:
|
2
2
|
#
|
3
3
|
# Object Methods
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# kernel/object
|
8
|
-
#
|
9
|
-
# DESCRIPTION:
|
5
|
+
# = DESCRIPTION:
|
10
6
|
#
|
11
7
|
# Kernel extension using object_ prefix which is beneficial
|
12
8
|
# to separation of metaprogramming from general programming.
|
13
9
|
# object_ methods, in contrast to the instance_ methods,
|
14
10
|
# do not access internal state.
|
15
11
|
#
|
16
|
-
# AUTHORS:
|
12
|
+
# = AUTHORS:
|
17
13
|
#
|
18
|
-
#
|
14
|
+
# - Thomas Sawyer
|
19
15
|
|
20
16
|
module Kernel
|
21
17
|
|
@@ -38,6 +34,16 @@ module Kernel
|
|
38
34
|
end
|
39
35
|
|
40
36
|
# Send only to public methods.
|
37
|
+
#
|
38
|
+
# class X
|
39
|
+
# private
|
40
|
+
# def foo; end
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# X.new.object_send(:foo)
|
44
|
+
# => NoMethodError: private method `foo' called for #<X:0xb7ac6ba8>
|
45
|
+
#
|
46
|
+
# CREDIT: Trans
|
41
47
|
#--
|
42
48
|
# Which implementation is faster?
|
43
49
|
#++
|
@@ -60,34 +66,3 @@ module Kernel
|
|
60
66
|
alias :__class__ :class
|
61
67
|
|
62
68
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
# _____ _
|
67
|
-
# |_ _|__ ___| |_
|
68
|
-
# | |/ _ \/ __| __|
|
69
|
-
# | | __/\__ \ |_
|
70
|
-
# |_|\___||___/\__|
|
71
|
-
#
|
72
|
-
=begin test
|
73
|
-
|
74
|
-
require 'test/unit'
|
75
|
-
|
76
|
-
class TCKernel < Test::Unit::TestCase
|
77
|
-
|
78
|
-
def test_object_class
|
79
|
-
assert_equal( self.class, self.object_class )
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_object_hexid
|
83
|
-
o = Object.new
|
84
|
-
assert( o.inspect.index( o.object_hexid ) )
|
85
|
-
end
|
86
|
-
|
87
|
-
def test__class__
|
88
|
-
assert_equal( self.class, self.__class__ )
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
=end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# TODO Is there any good way to avoid 'unless const_defined?'.
|
2
|
-
|
3
1
|
module Kernel
|
4
2
|
|
3
|
+
# TODO: Is there any good way to avoid 'unless const_defined?'.
|
4
|
+
|
5
5
|
unless const_defined?("OPERATORS")
|
6
6
|
OPERATORS = %w{ +@ -@ + - ** * / % ~ <=> << >> < > === == =~ <= >= | & ^ []= [] }
|
7
7
|
OPERATORS_REGEXP = Regexp.new( '(' << OPERATORS.collect{ |k| Regexp.escape(k) }.join('|') << ')' )
|
@@ -33,8 +33,30 @@ module Kernel
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
|
+
# Applies operator escape's according to OPERATORS_ESCAPE_TABLE.
|
37
|
+
#
|
38
|
+
# op_esc('-') #=> "op_minus"
|
39
|
+
#
|
40
|
+
# CREDIT: Trans
|
41
|
+
|
36
42
|
def op_esc( str )
|
37
43
|
str.gsub(OPERATORS_REGEXP){ OPERATORS_ESC_TABLE[$1] }
|
38
44
|
end
|
39
45
|
|
46
|
+
# NOTE: op_esc used to support the method require_esc.
|
47
|
+
#
|
48
|
+
# # Require a file with puncuation marks escaped.
|
49
|
+
# #
|
50
|
+
# # require_esc '[].rb'
|
51
|
+
# #
|
52
|
+
# # in actuality requires the file 'op_fetch.rb'.
|
53
|
+
#
|
54
|
+
# def require_esc( fpath )
|
55
|
+
# fdir, fname = File.split(fpath)
|
56
|
+
# ename = op_esc( fname )
|
57
|
+
# case ename[-1,1] ; when '!','=','?' then ename = ename[0...-1] ; end
|
58
|
+
# epath = File.join( fdir, ename )
|
59
|
+
# require( epath )
|
60
|
+
# end
|
61
|
+
|
40
62
|
end
|
@@ -1,23 +1,19 @@
|
|
1
|
-
# TITLE:
|
1
|
+
# = TITLE:
|
2
2
|
#
|
3
3
|
# Populate
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# kernel/populate.rb
|
8
|
-
#
|
9
|
-
# DESCRIPTION:
|
5
|
+
# = DESCRIPTION:
|
10
6
|
#
|
11
7
|
# Kernel extensions for setting object state or
|
12
8
|
# assigning variables.
|
13
9
|
#
|
14
|
-
# AUTHORS:
|
10
|
+
# = AUTHORS:
|
15
11
|
#
|
16
|
-
#
|
12
|
+
# - Thomas Sawyer
|
17
13
|
#
|
18
|
-
#
|
14
|
+
# = TODO:
|
19
15
|
#
|
20
|
-
#
|
16
|
+
# - Change these to fit with object_ and instance_ conventions (?)
|
21
17
|
|
22
18
|
#
|
23
19
|
module Kernel
|
@@ -138,62 +134,3 @@ module Kernel
|
|
138
134
|
end
|
139
135
|
|
140
136
|
end
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
# _____ _
|
146
|
-
# |_ _|__ ___| |_
|
147
|
-
# | |/ _ \/ __| __|
|
148
|
-
# | | __/\__ \ |_
|
149
|
-
# |_|\___||___/\__|
|
150
|
-
#
|
151
|
-
=begin test
|
152
|
-
|
153
|
-
require 'test/unit'
|
154
|
-
|
155
|
-
class TestKernelPopulate < Test::Unit::TestCase
|
156
|
-
|
157
|
-
# def test_assign_from
|
158
|
-
# o = Object.new
|
159
|
-
# o.instance_eval{ @z=0; @a=1; @b=2 } #; @@a=3 }
|
160
|
-
# assign_from( o, "z", "@a", "@b" ) #, "@@a" )
|
161
|
-
# assert_equal( 1, @a )
|
162
|
-
# assert_equal( 2, @b )
|
163
|
-
# #assert_equal( 3, @@a )
|
164
|
-
# end
|
165
|
-
|
166
|
-
Customer = Struct.new( "Customer", :name, :address, :zip )
|
167
|
-
|
168
|
-
def test_set_from
|
169
|
-
bob = Customer.new("Bob Sawyer", "123 Maple, Anytown NC", 12345)
|
170
|
-
joe = Customer.new("Joe Pitare")
|
171
|
-
joe.set_from(bob, :address, :zip)
|
172
|
-
assert_equal("Joe Pitare", joe.name)
|
173
|
-
assert_equal("123 Maple, Anytown NC", joe.address)
|
174
|
-
assert_equal(12345, joe.zip)
|
175
|
-
end
|
176
|
-
|
177
|
-
Customer = Struct.new( "Customer", :name, :address, :zip )
|
178
|
-
|
179
|
-
def test_hash
|
180
|
-
bob = Customer.new()
|
181
|
-
x = { :name => "Bob Sawyer", :address => "123 Maple, Anytown NC", :zip => 12345 }
|
182
|
-
bob.set_with(x)
|
183
|
-
assert_equal(x[:name], bob.name)
|
184
|
-
assert_equal(x[:address], bob.address)
|
185
|
-
assert_equal(x[:zip], bob.zip)
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_block
|
189
|
-
bob = Customer.new()
|
190
|
-
x = lambda {|s| s.name = "Bob Sawyer"; s.address = "123 Maple, Anytown NC"; s.zip = 12345 }
|
191
|
-
bob.set_with(&x)
|
192
|
-
assert_equal("Bob Sawyer", bob.name)
|
193
|
-
assert_equal("123 Maple, Anytown NC", bob.address)
|
194
|
-
assert_equal(12345, bob.zip)
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
=end
|
@@ -1,36 +1,29 @@
|
|
1
|
-
# TITLE:
|
2
|
-
#
|
3
|
-
# Reporting Extensions
|
4
|
-
#
|
5
|
-
# DESCRIPTION:
|
6
|
-
#
|
7
|
-
# Kernel extensions for debugging, warning and demoing.
|
8
|
-
#
|
9
|
-
# AUTHORS:
|
10
|
-
#
|
11
|
-
# - TransDelabug
|
12
|
-
|
13
1
|
module Kernel
|
2
|
+
|
14
3
|
module_function
|
15
4
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
5
|
+
unless (RUBY_VERSION[0,3] == '1.9')
|
6
|
+
|
7
|
+
# Alternate to standard #p method that outputs
|
8
|
+
# Kernel#inspect to stdout, but also passes through
|
9
|
+
# the orginal argument(s).
|
10
|
+
#
|
11
|
+
# x = 1
|
12
|
+
# r = 4 + q(1)
|
13
|
+
# p r
|
14
|
+
#
|
15
|
+
# produces
|
16
|
+
#
|
17
|
+
# 1
|
18
|
+
# 5
|
19
|
+
#
|
20
|
+
# DEPRECATE AS OF 1.9, _if_ #p will then do this too.
|
21
|
+
|
22
|
+
def p(*x)
|
23
|
+
x.each{ |e| puts e.inspect } #p(*x)
|
24
|
+
x.size > 1 ? x : x.last #x.last
|
25
|
+
end
|
30
26
|
|
31
|
-
def p(*x)
|
32
|
-
x.each{ |e| puts e.inspect } #p(*x)
|
33
|
-
x.size > 1 ? x : x.last #x.last
|
34
27
|
end
|
35
28
|
|
36
29
|
# Like #p but gives file and line number.
|
@@ -56,6 +49,10 @@ module Kernel
|
|
56
49
|
#
|
57
50
|
# Output:
|
58
51
|
# The pretty printed string.
|
52
|
+
#
|
53
|
+
# TODO: Deprecate in favor of Exception#detail.
|
54
|
+
#
|
55
|
+
# CREDIT: George Moschovitis
|
59
56
|
|
60
57
|
def pp_exception(ex)
|
61
58
|
return %{#{ex.message}\n #{ex.backtrace.join("\n ")}\n LOGGED FROM: #{caller[0]}}
|
@@ -74,10 +71,8 @@ module Kernel
|
|
74
71
|
# a.slice(1,2) #=> [2, 3]
|
75
72
|
# a.map { |x| x**3 } #=> [1, 8, 27]
|
76
73
|
#
|
77
|
-
|
78
|
-
#
|
79
|
-
# Preferably just a block and no string.
|
80
|
-
#++
|
74
|
+
# TODO: Is there a way to do this without the eval string in block?
|
75
|
+
# Preferably just a block and no string.
|
81
76
|
|
82
77
|
def demo(out=$stdout,&block)
|
83
78
|
out << sprintf("%-25s#=> %s\n", expr = block.call, eval(expr, block.binding).inspect)
|
@@ -1,18 +1,14 @@
|
|
1
|
-
# TITLE:
|
1
|
+
# = TITLE:
|
2
2
|
#
|
3
3
|
# Require / Load Extensions
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# requires.rb
|
8
|
-
#
|
9
|
-
# DESCRIPTION:
|
5
|
+
# = DESCRIPTION:
|
10
6
|
#
|
11
7
|
# Require/Load extensions.
|
12
8
|
#
|
13
|
-
# AUTHORS:
|
9
|
+
# = AUTHORS:
|
14
10
|
#
|
15
|
-
#
|
11
|
+
# - Thomas Sawyer
|
16
12
|
|
17
13
|
#
|
18
14
|
module Kernel
|
@@ -23,7 +19,7 @@ module Kernel
|
|
23
19
|
#
|
24
20
|
# load_local 'templib'
|
25
21
|
#
|
26
|
-
def load_local(
|
22
|
+
def load_local(fname, safe=nil)
|
27
23
|
#fdir = File.expand_path( File.dirname( caller[0] ) )
|
28
24
|
fdir = File.dirname( caller[0] )
|
29
25
|
load( File.join( fdir, fname ), safe )
|
@@ -33,7 +29,7 @@ module Kernel
|
|
33
29
|
#
|
34
30
|
# require_local 'templib'
|
35
31
|
#
|
36
|
-
def require_local(
|
32
|
+
def require_local(fname)
|
37
33
|
#fdir = File.expand_path( File.dirname( caller[0] ) )
|
38
34
|
fdir = File.dirname( caller[0] )
|
39
35
|
require( File.join( fdir, fname ) )
|
@@ -44,7 +40,7 @@ module Kernel
|
|
44
40
|
#
|
45
41
|
# require_all 'facets/time/*'
|
46
42
|
#
|
47
|
-
def require_all(
|
43
|
+
def require_all(pat)
|
48
44
|
$LOAD_PATH.each do |path|
|
49
45
|
fs = Dir[File.join(path,pat)]
|
50
46
|
unless fs.empty?
|
@@ -57,13 +53,3 @@ module Kernel
|
|
57
53
|
end
|
58
54
|
|
59
55
|
end
|
60
|
-
|
61
|
-
|
62
|
-
# _____ _
|
63
|
-
# |_ _|__ ___| |_
|
64
|
-
# | |/ _ \/ __| __|
|
65
|
-
# | | __/\__ \ |_
|
66
|
-
# |_|\___||___/\__|
|
67
|
-
#
|
68
|
-
# NO RESONABLE WAY TO DO
|
69
|
-
# (THAT I CAN THINK OF)
|
@@ -3,11 +3,21 @@ module Kernel
|
|
3
3
|
# Like #respond_to? but returns the result of the call
|
4
4
|
# if it does indeed respond.
|
5
5
|
#
|
6
|
-
#
|
6
|
+
# class X
|
7
|
+
# def f; "f"; end
|
8
|
+
# end
|
7
9
|
#
|
10
|
+
# x = X.new
|
11
|
+
# x.respond(:f) #=> "f"
|
12
|
+
# x.respond(:g) #=> nil
|
13
|
+
#
|
14
|
+
# CREDIT: Trans
|
15
|
+
|
8
16
|
def respond(sym, *args)
|
9
17
|
return nil if not respond_to?(sym, *args)
|
10
18
|
send(sym, *args)
|
11
19
|
end
|
12
20
|
|
21
|
+
alias_method :respond_with_value, :respond
|
22
|
+
|
13
23
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
# A Ruby-ized realization of the K combinator.
|
4
|
+
#
|
5
|
+
# returning Book.new do |book|
|
6
|
+
# book.title = "Imperium"
|
7
|
+
# book.author = "Ulick Varange"
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Also aliased as #with.
|
11
|
+
#
|
12
|
+
# def foo
|
13
|
+
# with values = [] do
|
14
|
+
# values << 'bar'
|
15
|
+
# values << 'baz'
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# foo # => ['bar', 'baz']
|
20
|
+
#
|
21
|
+
# Technically, #returning probably should force the return of
|
22
|
+
# the stated object irregardless of any return statements that
|
23
|
+
# might appear within it's block. This might differentiate
|
24
|
+
# #returning from #with, however it also would require
|
25
|
+
# implementation in Ruby itself.
|
26
|
+
#
|
27
|
+
# CREDIT: Mikael Brockman
|
28
|
+
|
29
|
+
def returning(obj=self)
|
30
|
+
yield obj
|
31
|
+
obj
|
32
|
+
end
|
33
|
+
|
34
|
+
alias_method :with, :returning
|
35
|
+
|
36
|
+
# Repeat loop until it yeilds false or nil.
|
37
|
+
#
|
38
|
+
# a = [3, 2, 1]
|
39
|
+
# complete do
|
40
|
+
# b << a.pop
|
41
|
+
# end
|
42
|
+
# b #=> [3, 2, 1, nil]
|
43
|
+
#
|
44
|
+
# CREDIT: Trans
|
45
|
+
|
46
|
+
def complete
|
47
|
+
loop { break unless yield }
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
# TITLE:
|
1
|
+
# = TITLE:
|
2
2
|
# Verbosity Reporting Extensions
|
3
3
|
#
|
4
|
-
# DESCRIPTION:
|
4
|
+
# = DESCRIPTION:
|
5
5
|
# Kernel extensions dealing with verbosity of warnings
|
6
6
|
# and error messages.
|
7
7
|
#
|
8
|
-
# AUTHORS:
|
8
|
+
# = AUTHORS:
|
9
9
|
# - David Heinemeier Hansson
|
10
10
|
# - TransSilentNight
|
11
11
|
#
|
12
|
-
# LOG:
|
12
|
+
# = LOG:
|
13
13
|
# - trans 07.09.01 Deprecated #silently as alias of slience_warnings.
|
14
14
|
|
15
15
|
module Kernel
|
@@ -22,6 +22,9 @@ module Kernel
|
|
22
22
|
# end
|
23
23
|
#
|
24
24
|
# puts 'But this will'
|
25
|
+
#
|
26
|
+
# CREDIT: David Heinemeier Hansson
|
27
|
+
|
25
28
|
def silence_stream(stream)
|
26
29
|
old_stream = stream.dup
|
27
30
|
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
@@ -32,7 +35,7 @@ module Kernel
|
|
32
35
|
end
|
33
36
|
#alias_method :silently, :silence_stream
|
34
37
|
|
35
|
-
# For compatibility
|
38
|
+
# For compatibility.
|
36
39
|
def silence_stderr #:nodoc:
|
37
40
|
silence_stream(STDERR) { yield }
|
38
41
|
end
|
@@ -44,7 +47,8 @@ module Kernel
|
|
44
47
|
# value = noisy_call # no warning voiced
|
45
48
|
# end
|
46
49
|
#
|
47
|
-
# noisy_call
|
50
|
+
# noisy_call # no warning is voiced
|
51
|
+
|
48
52
|
def silence_warnings
|
49
53
|
old_verbose, $VERBOSE = $VERBOSE, nil
|
50
54
|
yield
|
@@ -62,6 +66,8 @@ module Kernel
|
|
62
66
|
end
|
63
67
|
|
64
68
|
# Supress errors while executing a block, with execptions.
|
69
|
+
#
|
70
|
+
# CREDIT: David Heinemeier Hansson
|
65
71
|
|
66
72
|
def suppress(*exception_classes)
|
67
73
|
begin yield
|
@@ -71,21 +77,3 @@ module Kernel
|
|
71
77
|
end
|
72
78
|
|
73
79
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
=begin test
|
78
|
-
|
79
|
-
require 'test/unit'
|
80
|
-
|
81
|
-
class TestKernelError < Test::Unit::TestCase
|
82
|
-
|
83
|
-
def test_silently
|
84
|
-
silently do
|
85
|
-
assert( ! $VERBOSE )
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
=end
|