facets 2.9.0 → 2.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.rdoc +34 -0
- data/{meta/profile → PROFILE} +15 -1
- data/README.rdoc +11 -17
- data/Rakefile +74 -31
- data/VERSION +1 -0
- data/lib/core-uncommon/facets/array/median.rb +17 -0
- data/lib/core-uncommon/facets/array/op_pow.rb +9 -0
- data/lib/{tour → core-uncommon}/facets/array/percentile.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/class/preallocate.rb +3 -0
- data/lib/core-uncommon/facets/enumerable/has.rb +22 -0
- data/lib/core-uncommon/facets/enumerable/have.rb +1 -0
- data/lib/{tour → core-uncommon}/facets/integer/roman.rb +9 -0
- data/lib/{tour → core-uncommon}/facets/kernel/demo.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/kernel/eigenclass.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/kernel/instance_exec.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/kernel/memo.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/kernel/trap_chain.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/kernel/y.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/method/memoize.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/attr_class_accessor.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/module/attr_inheritor.rb +2 -0
- data/lib/{tour → core-uncommon}/facets/module/attr_tester.rb +8 -0
- data/lib/{tour → core-uncommon}/facets/module/attr_validator.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/module/cattr.rb +24 -0
- data/lib/core-uncommon/facets/module/class_accessor.rb +33 -0
- data/lib/{tour → core-uncommon}/facets/module/class_extend.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/class_inheritor.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/copy_inheritor.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/enclosure.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/module/enclosures.rb +0 -0
- data/lib/{tour → core-uncommon}/facets/module/include_as.rb +0 -0
- data/lib/{tour → core-uncommon}/facets/module/instance_function.rb +2 -0
- data/lib/{tour → core-uncommon}/facets/module/memoize.rb +0 -0
- data/lib/{tour → core-uncommon}/facets/module/method_space.rb +5 -0
- data/lib/{tour → core-uncommon}/facets/module/module_load.rb +6 -0
- data/lib/{tour → core-uncommon}/facets/module/preextend.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/module/prepend.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/regexp/op_or.rb +2 -0
- data/lib/{tour → core-uncommon}/facets/string/crypt.rb +3 -0
- data/lib/{tour → core-uncommon}/facets/string/roman.rb +0 -0
- data/lib/core/facets.rb +19 -0
- data/lib/core/facets.yml +1144 -0
- data/lib/core/facets/applique/file_helpers.rb +4 -4
- data/lib/core/facets/array.rb +0 -1
- data/lib/core/facets/binding.rb +1 -1
- data/lib/core/facets/class.rb +1 -1
- data/lib/core/facets/comparable.rb +1 -1
- data/lib/core/facets/dir.rb +1 -1
- data/lib/core/facets/dir/recurse.rb +1 -1
- data/lib/core/facets/enumerable.rb +1 -1
- data/lib/core/facets/exception.rb +1 -1
- data/lib/core/facets/file.rb +1 -1
- data/lib/core/facets/file/create.rb +1 -1
- data/lib/core/facets/file/read_binary.rb +2 -2
- data/lib/core/facets/file/rewrite.rb +4 -4
- data/lib/core/facets/file/write.rb +1 -1
- data/lib/core/facets/file/writelines.rb +1 -1
- data/lib/core/facets/filetest.rb +1 -1
- data/lib/core/facets/filetest/absolute.rb +1 -0
- data/lib/core/facets/filetest/contains.rb +12 -0
- data/lib/core/facets/filetest/relative.rb +38 -0
- data/lib/core/facets/filetest/safe.rb +20 -0
- data/lib/core/facets/filetest/separator_pattern.rb +19 -0
- data/lib/core/facets/float.rb +1 -1
- data/lib/core/facets/hash.rb +1 -1
- data/lib/core/facets/integer.rb +1 -1
- data/lib/core/facets/kernel.rb +1 -1
- data/lib/core/facets/kernel/no.rb +1 -0
- data/lib/core/facets/kernel/object_hexid.rb +3 -1
- data/lib/core/facets/kernel/yes.rb +25 -0
- data/lib/core/facets/matchdata.rb +1 -1
- data/lib/core/facets/method.rb +1 -1
- data/lib/core/facets/module.rb +1 -1
- data/lib/core/facets/module/redefine_method.rb +4 -4
- data/lib/core/facets/nilclass.rb +1 -1
- data/lib/core/facets/numeric.rb +1 -1
- data/lib/core/facets/object.rb +1 -1
- data/lib/core/facets/object/replace.rb +2 -2
- data/lib/core/facets/objectspace.rb +1 -1
- data/lib/core/facets/proc.rb +1 -1
- data/lib/core/facets/process.rb +1 -1
- data/lib/core/facets/range.rb +1 -1
- data/lib/core/facets/regexp.rb +1 -1
- data/lib/core/facets/string.rb +1 -1
- data/lib/core/facets/string/file.rb +4 -2
- data/lib/core/facets/string/random_binary.rb +10 -0
- data/lib/core/facets/string/unquote.rb +1 -1
- data/lib/core/facets/struct.rb +1 -1
- data/lib/core/facets/symbol.rb +1 -1
- data/lib/core/facets/time.rb +1 -1
- data/lib/core/facets/unboundmethod.rb +1 -1
- data/lib/{more → standard}/facets/basicobject.rb +0 -0
- data/lib/{more → standard}/facets/cgi.rb +0 -0
- data/lib/{more → standard}/facets/continuation.rb +0 -0
- data/lib/{more → standard}/facets/date.rb +0 -0
- data/lib/standard/facets/digest.rb +2 -0
- data/lib/standard/facets/digest/base64digest.rb +45 -0
- data/lib/standard/facets/digest/salted_digest.rb +44 -0
- data/lib/{more → standard}/facets/erb.rb +0 -0
- data/lib/{more → standard}/facets/fileutils.rb +5 -0
- data/lib/standard/facets/fileutils/amass.rb +33 -0
- data/lib/{more → standard}/facets/fileutils/cp_rx.rb +3 -1
- data/lib/{more → standard}/facets/fileutils/head.rb +0 -0
- data/lib/standard/facets/fileutils/ln_r.rb +92 -0
- data/lib/standard/facets/fileutils/outofdate.rb +38 -0
- data/lib/{more → standard}/facets/fileutils/safe_ln.rb +0 -0
- data/lib/{more → standard}/facets/fileutils/slice.rb +14 -12
- data/lib/standard/facets/fileutils/stage.rb +66 -0
- data/lib/{more → standard}/facets/fileutils/tail.rb +0 -0
- data/lib/{more → standard}/facets/fileutils/wc.rb +0 -0
- data/lib/{more → standard}/facets/fileutils/whereis.rb +0 -0
- data/lib/{more → standard}/facets/fileutils/which.rb +2 -0
- data/lib/{more → standard}/facets/find.rb +0 -0
- data/lib/{more → standard}/facets/getoptlong.rb +0 -0
- data/lib/{more → standard}/facets/math.rb +1 -1
- data/lib/{more → standard}/facets/math/abs.rb +0 -0
- data/lib/{more → standard}/facets/math/acot.rb +0 -0
- data/lib/{more → standard}/facets/math/acoth.rb +0 -0
- data/lib/{more → standard}/facets/math/acsc.rb +0 -0
- data/lib/{more → standard}/facets/math/acsch.rb +0 -0
- data/lib/{more → standard}/facets/math/amd.rb +0 -0
- data/lib/{more → standard}/facets/math/approx_equal.rb +1 -1
- data/lib/{more → standard}/facets/math/asec.rb +0 -0
- data/lib/{more → standard}/facets/math/asech.rb +0 -0
- data/lib/{more → standard}/facets/math/atkinson_index.rb +0 -0
- data/lib/{more → standard}/facets/math/beta.rb +0 -0
- data/lib/{more → standard}/facets/math/cdf.rb +0 -0
- data/lib/{more → standard}/facets/math/ceil.rb +0 -0
- data/lib/{more → standard}/facets/math/cot.rb +0 -0
- data/lib/{more → standard}/facets/math/coth.rb +0 -0
- data/lib/{more → standard}/facets/math/csc.rb +0 -0
- data/lib/{more → standard}/facets/math/csch.rb +0 -0
- data/lib/{more → standard}/facets/math/delta.rb +2 -1
- data/lib/{more → standard}/facets/math/epsilon.rb +0 -0
- data/lib/{more → standard}/facets/math/exp10.rb +0 -0
- data/lib/{more → standard}/facets/math/exp2.rb +0 -0
- data/lib/{more → standard}/facets/math/factorial.rb +0 -0
- data/lib/{more → standard}/facets/math/floor.rb +0 -0
- data/lib/{more → standard}/facets/math/gamma.rb +0 -0
- data/lib/{more → standard}/facets/math/gcd.rb +0 -0
- data/lib/{more → standard}/facets/math/gini_coefficient.rb +0 -0
- data/lib/{more → standard}/facets/math/kldivergence.rb +0 -0
- data/lib/{more → standard}/facets/math/lcm.rb +0 -0
- data/lib/{more → standard}/facets/math/lgamma.rb +0 -0
- data/lib/{more → standard}/facets/math/linsolve.rb +0 -0
- data/lib/{more → standard}/facets/math/log2.rb +0 -0
- data/lib/{more → standard}/facets/math/max.rb +0 -0
- data/lib/{more → standard}/facets/math/mean.rb +0 -0
- data/lib/{more → standard}/facets/math/median.rb +0 -0
- data/lib/{more → standard}/facets/math/min.rb +0 -0
- data/lib/{more → standard}/facets/math/pow.rb +0 -0
- data/lib/{more → standard}/facets/math/pstd.rb +0 -0
- data/lib/{more → standard}/facets/math/pvariance.rb +0 -0
- data/lib/{more → standard}/facets/math/rmd.rb +0 -0
- data/lib/{more → standard}/facets/math/root.rb +0 -0
- data/lib/{more → standard}/facets/math/sec.rb +0 -0
- data/lib/{more → standard}/facets/math/sech.rb +0 -0
- data/lib/{more → standard}/facets/math/sign.rb +0 -0
- data/lib/{more → standard}/facets/math/sinc.rb +0 -0
- data/lib/{more → standard}/facets/math/sqr.rb +0 -0
- data/lib/{more → standard}/facets/math/sqsolve.rb +0 -0
- data/lib/{more → standard}/facets/math/std.rb +0 -0
- data/lib/{more → standard}/facets/math/stderr.rb +0 -0
- data/lib/{more → standard}/facets/math/sum.rb +0 -0
- data/lib/{more → standard}/facets/math/summed_sqdevs.rb +0 -0
- data/lib/{more → standard}/facets/math/theil_index.rb +0 -0
- data/lib/{more → standard}/facets/math/variance.rb +0 -0
- data/lib/standard/facets/net/http.rb +32 -0
- data/lib/{more → standard}/facets/ostruct.rb +0 -0
- data/lib/{more → standard}/facets/pathname.rb +1 -0
- data/lib/{more → standard}/facets/random.rb +2 -2
- data/lib/standard/facets/rbconfig.rb +78 -0
- data/lib/{more → standard}/facets/set.rb +0 -0
- data/lib/{more → standard}/facets/shellwords.rb +2 -0
- data/lib/standard/facets/strscan.rb +16 -0
- data/lib/{more → standard}/facets/thread.rb +0 -0
- data/lib/{more → standard}/facets/uri.rb +0 -0
- data/lib/{more → standard}/facets/yaml.rb +0 -0
- data/lib/{more → standard}/facets/zlib.rb +0 -0
- data/lib/{more → supplemental}/facets/argvector.rb +0 -0
- data/lib/{more → supplemental}/facets/atomicfile.rb +0 -0
- data/lib/{more → supplemental}/facets/interval.rb +0 -0
- data/lib/{more → supplemental}/facets/main.rb +0 -0
- data/lib/{more → supplemental}/facets/memoizable.rb +0 -0
- data/lib/{more → supplemental}/facets/metaid.rb +0 -0
- data/lib/{more → supplemental}/facets/multipliers.rb +0 -0
- data/lib/{more → supplemental}/facets/multiton.rb +0 -0
- data/lib/{more → supplemental}/facets/nullclass.rb +0 -0
- data/lib/{more → supplemental}/facets/opesc.rb +0 -0
- data/lib/{more → supplemental}/facets/platform.rb +156 -5
- data/lib/{more → supplemental}/facets/reference.rb +0 -0
- data/lib/{more → supplemental}/facets/timer.rb +0 -0
- data/lib/{more → supplemental}/facets/tuple.rb +0 -0
- data/qed/applique/file_helpers.rb +10 -0
- data/qed/{tour → core-uncommon}/module/cattr.rdoc +0 -0
- data/qed/{tour → core-uncommon}/module/class_extend.rdoc +0 -0
- data/qed/{tour → core-uncommon}/module/class_inheritor.rdoc +0 -0
- data/qed/{tour → core-uncommon}/module/copy_inheritor.rdoc +0 -0
- data/qed/{tour → core-uncommon}/module/method_space.rdoc +0 -0
- data/qed/{more → standard}/basic_object.rdoc +0 -0
- data/qed/{more → supplemental}/memoizable.rdoc +0 -0
- data/qed/{more → supplemental}/mulititon.rdoc +0 -0
- data/test/{tour → core-uncommon}/array/test_median.rb +0 -0
- data/test/{tour → core-uncommon}/array/test_percentile.rb +0 -0
- data/test/{tour → core-uncommon}/class/test_preallocate.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_cattr.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_class_extend.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_class_inheritor.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_copy_inheritor.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_enclosure.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_instance_function.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_memoize.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_method_space.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_module_load.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_preextend.rb +0 -0
- data/test/{tour → core-uncommon}/module/test_prepend.rb +0 -0
- data/test/core/dir/test_each_child.rb +1 -1
- data/test/core/dir/test_multiglob.rb +2 -2
- data/test/core/hash/test_zip.rb +12 -0
- data/test/core/{kernel → object}/test_dup.rb +51 -1
- data/test/core/{kernel → object}/test_object_state.rb +1 -1
- data/test/core/{kernel → object}/test_replace.rb +12 -12
- data/test/core/{kernel → object}/test_try_dup.rb +2 -2
- data/test/{more → standard}/test_date.rb +0 -0
- data/test/{more → standard}/test_ostruct.rb +0 -0
- data/test/{more → standard}/test_random.rb +0 -0
- data/test/{more → standard}/test_shellwords.rb +0 -0
- data/test/{more → standard}/test_thread.rb +0 -0
- data/test/{more → standard}/test_timer.rb +0 -0
- data/test/{more → standard}/test_uri.rb +0 -0
- data/test/{more → supplemental}/test_argvector.rb +0 -0
- data/test/{more → supplemental}/test_memoizable.rb +0 -0
- data/test/{more → supplemental}/test_multipliers.rb +0 -0
- data/test/{more → supplemental}/test_tuple.rb +0 -0
- metadata +224 -204
- data/lib/more/facets/rbconfig.rb +0 -150
- data/lib/tour/facets/array/median.rb +0 -14
- data/lib/tour/facets/array/op_pow.rb +0 -5
- data/lib/tour/facets/module/class_accessor.rb +0 -27
- data/meta/data.rb +0 -29
- data/meta/package +0 -10
- data/test/core/hash/test_zipnew.rb +0 -12
@@ -23,11 +23,11 @@ end
|
|
23
23
|
|
24
24
|
# Used for File extensions
|
25
25
|
When "had a file '(((.*?)))'" do |name|
|
26
|
-
name = name.sub(/^tmp\//, '')
|
27
|
-
File.open(
|
26
|
+
name = name.sub(/^tmp\//, '') # b/c QED now runs from tmp/qed
|
27
|
+
File.open(name, 'w'){|f| f << "Hello World"}
|
28
28
|
end
|
29
29
|
|
30
30
|
When "had a binary file '(((.*?)))'" do |name|
|
31
|
-
name = name.sub(/^tmp\//, '')
|
32
|
-
File.open(
|
31
|
+
name = name.sub(/^tmp\//, '') # b/c QED now runs from tmp/qed
|
32
|
+
File.open(name, 'wb'){|f| f << "Hello\nWorld\n"}
|
33
33
|
end
|
data/lib/core/facets/array.rb
CHANGED
data/lib/core/facets/binding.rb
CHANGED
data/lib/core/facets/class.rb
CHANGED
data/lib/core/facets/dir.rb
CHANGED
data/lib/core/facets/file.rb
CHANGED
@@ -2,9 +2,9 @@ class File
|
|
2
2
|
|
3
3
|
# Read in a file as binary data.
|
4
4
|
#
|
5
|
-
# Assuming we had a binary file '
|
5
|
+
# Assuming we had a binary file 'binary.dat'.
|
6
6
|
#
|
7
|
-
# File.read_binary('
|
7
|
+
# File.read_binary('binary.dat')
|
8
8
|
#
|
9
9
|
# CREDIT: George Moschovitis
|
10
10
|
|
@@ -16,10 +16,10 @@ class File
|
|
16
16
|
# Assuming we had a file 'message.txt' and had a binary file 'binary.dat'.
|
17
17
|
#
|
18
18
|
# # Reverse contents of "message.txt"
|
19
|
-
# File.rewrite("
|
19
|
+
# File.rewrite("message.txt") { |str| str.reverse }
|
20
20
|
#
|
21
21
|
# # Replace "foo" by "bar" in "binary.dat".
|
22
|
-
# File.rewrite("
|
22
|
+
# File.rewrite("binary.dat", "b") { |str| str.gsub("foo", "bar") }
|
23
23
|
#
|
24
24
|
# IMPORTANT: The old version of this method required in place modification
|
25
25
|
# of the file string. The new version will write whatever the block
|
@@ -56,10 +56,10 @@ class File
|
|
56
56
|
# string be modified in place within the block.
|
57
57
|
#
|
58
58
|
# # Reverse contents of "message"
|
59
|
-
# File.rewrite("
|
59
|
+
# File.rewrite("message.txt") { |str| str.reverse! }
|
60
60
|
#
|
61
61
|
# # Replace "foo" by "bar" in "binary"
|
62
|
-
# File.rewrite("
|
62
|
+
# File.rewrite("binary.dat", "b") { |str| str.gsub!("foo", "bar") }
|
63
63
|
#
|
64
64
|
def self.rewrite!(name, mode = "") #:yield:
|
65
65
|
unless block_given?
|
data/lib/core/facets/filetest.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/filetest/relative'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'facets/filetest/separator_pattern'
|
2
|
+
|
3
|
+
module FileTest
|
4
|
+
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Predicate method for testing whether a path is absolute.
|
8
|
+
# It returns +true+ if the pathname begins with a slash.
|
9
|
+
def absolute?(path)
|
10
|
+
!relative?(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
# The opposite of #absolute?
|
14
|
+
def relative?(path)
|
15
|
+
while r = chop_basename(path.to_s)
|
16
|
+
path, basename = r
|
17
|
+
end
|
18
|
+
path == ''
|
19
|
+
end
|
20
|
+
|
21
|
+
# List File.split, but preserves the file separators.
|
22
|
+
#
|
23
|
+
# FileTest.chop_basename('/usr/lib') #=> ['/usr/', 'lib']
|
24
|
+
# FileTest.chop_basename('/') #=> nil
|
25
|
+
#
|
26
|
+
# Returns Array of `[pre-basename, basename]` or `nil`.
|
27
|
+
#
|
28
|
+
# This method is here simply to support the #relative? and #absolute? methods.
|
29
|
+
def chop_basename(path)
|
30
|
+
base = File.basename(path)
|
31
|
+
if /\A#{SEPARATOR_PATTERN}?\z/ =~ base
|
32
|
+
return nil
|
33
|
+
else
|
34
|
+
return path[0, path.rindex(base)], base
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'facets/filetest/separator_pattern'
|
2
|
+
|
3
|
+
module FileTest
|
4
|
+
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Is a path considered reasonably "safe"?
|
8
|
+
#
|
9
|
+
# Do not mistake this for a perfect solution!
|
10
|
+
def safe?(path)
|
11
|
+
case path
|
12
|
+
when /\A(#{SEPARATOR_PATTERN}|\~)(#{SEPARATOR_PATTERN}|\*)+/
|
13
|
+
false
|
14
|
+
else
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FileTest
|
2
|
+
|
3
|
+
#
|
4
|
+
SEPARATOR_PATTERN = (
|
5
|
+
if File::ALT_SEPARATOR
|
6
|
+
/[#{Regexp.quote File::ALT_SEPARATOR}#{Regexp.quote File::SEPARATOR}]/
|
7
|
+
else
|
8
|
+
/#{Regexp.quote File::SEPARATOR}/
|
9
|
+
end
|
10
|
+
).freeze
|
11
|
+
|
12
|
+
#module_function
|
13
|
+
#
|
14
|
+
# #
|
15
|
+
# def separator_pattern
|
16
|
+
# SEPARATOR_PATTERN
|
17
|
+
# end
|
18
|
+
|
19
|
+
end
|
data/lib/core/facets/float.rb
CHANGED
data/lib/core/facets/hash.rb
CHANGED
data/lib/core/facets/integer.rb
CHANGED
data/lib/core/facets/kernel.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'facets/kernel/yes'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'facets/kernel/ask'
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
|
5
|
+
# Ask a question expecting a yes answer.
|
6
|
+
def yes?(question)
|
7
|
+
case ask(question).downcase
|
8
|
+
when 'y', 'yes'
|
9
|
+
true
|
10
|
+
else
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Ask a question expecting a no answer.
|
16
|
+
def no?(question)
|
17
|
+
case ask(question).downcase
|
18
|
+
when 'n', 'no'
|
19
|
+
true
|
20
|
+
else
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/core/facets/method.rb
CHANGED
data/lib/core/facets/module.rb
CHANGED
@@ -24,10 +24,10 @@ class Module
|
|
24
24
|
# CREDIT: Trans
|
25
25
|
|
26
26
|
def redefine_method(sym, aka=nil, &blk)
|
27
|
-
raise ArgumentError, "method does not exist" unless method_defined?( sym )
|
28
|
-
alias_method(
|
29
|
-
undef_method(
|
30
|
-
define_method(
|
27
|
+
#raise ArgumentError, "method does not exist" unless method_defined?( sym )
|
28
|
+
alias_method(aka, sym) if aka
|
29
|
+
undef_method(sym)
|
30
|
+
define_method(sym, &blk)
|
31
31
|
end
|
32
32
|
|
33
33
|
alias_method :redef, :redefine_method
|
data/lib/core/facets/nilclass.rb
CHANGED
data/lib/core/facets/numeric.rb
CHANGED
data/lib/core/facets/object.rb
CHANGED
@@ -25,7 +25,7 @@ class Object
|
|
25
25
|
# This is very similar to <code>instance.update</code>, but it is limited
|
26
26
|
# by the class of objects, in the same manner as Array#replace.
|
27
27
|
def replace(source)
|
28
|
-
raise ArgumentError, "not a #{self.class}" unless source.is_a?(self.class)
|
28
|
+
raise ArgumentError, "not a #{self.class} -- #{source}" unless source.is_a?(self.class)
|
29
29
|
instance_variables.each do |iv|
|
30
30
|
instance_variable_set(iv, source.instance_variable_get(iv))
|
31
31
|
end
|
@@ -35,7 +35,7 @@ end
|
|
35
35
|
|
36
36
|
class Struct
|
37
37
|
|
38
|
-
# Struct#replace can take
|
38
|
+
# Struct#replace can take any +source+ that responds to #each_pair.
|
39
39
|
def replace(source)
|
40
40
|
source.each_pair{ |k,v| send(k.to_s + "=", v) }
|
41
41
|
end
|