extensions 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +12 -0
- data/HISTORY +59 -59
- data/InstalledFiles +50 -0
- data/README +19 -8
- data/README.1st +11 -11
- data/Rakefile +6 -0
- data/VERSION +1 -1
- data/bin/rbxtm +13 -13
- data/etc/website/index.html +10 -10
- data/install.rb +1098 -1098
- data/install.sh +3 -3
- data/lib/extensions/_base.rb +153 -153
- data/lib/extensions/_template.rb +36 -36
- data/lib/extensions/all.rb +19 -17
- data/lib/extensions/array.rb +24 -24
- data/lib/extensions/binding.rb +224 -0
- data/lib/extensions/class.rb +50 -50
- data/lib/extensions/continuation.rb +71 -0
- data/lib/extensions/hash.rb +23 -23
- data/lib/extensions/io.rb +58 -58
- data/lib/extensions/numeric.rb +204 -204
- data/lib/extensions/object.rb +164 -164
- data/lib/extensions/string.rb +316 -316
- data/lib/extensions/symbol.rb +28 -28
- data/test/tc_binding.rb +87 -0
- data/test/tc_continuation.rb +38 -0
- metadata +11 -11
data/test/tc_binding.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'extensions/binding'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Special test case for Binding#of_caller.
|
6
|
+
#
|
7
|
+
class TC_Binding_of_caller < Test::Unit::TestCase
|
8
|
+
#
|
9
|
+
# Tests Binding.of_caller
|
10
|
+
#
|
11
|
+
def test_of_caller
|
12
|
+
x = 5
|
13
|
+
_foo # This will increment x.
|
14
|
+
assert_equal 6, x
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Test the exception that should result if Binding.of_caller is used incorrectly.
|
19
|
+
#
|
20
|
+
def test_of_caller_exception
|
21
|
+
x = 10
|
22
|
+
assert_raises(Exception) do
|
23
|
+
_bar
|
24
|
+
puts x
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Use Binding.of_caller correctly.
|
29
|
+
def _foo
|
30
|
+
Binding.of_caller do |b|
|
31
|
+
eval "x += 1", b
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Use Binding.of_caller incorrectly (dangling code).
|
36
|
+
def _bar
|
37
|
+
Binding.of_caller do |b|
|
38
|
+
eval "x += 1", b
|
39
|
+
end
|
40
|
+
"foo".strip! # This code not allowed to be here.
|
41
|
+
end
|
42
|
+
end # class TC_Binding_of_caller
|
43
|
+
|
44
|
+
|
45
|
+
#
|
46
|
+
# Test case for the other Binding methods.
|
47
|
+
#
|
48
|
+
class TC_Binding < Test::Unit::TestCase
|
49
|
+
|
50
|
+
# Test all the Binding methods except of_caller.
|
51
|
+
def test_binding_methods
|
52
|
+
x = y = 5
|
53
|
+
b = binding
|
54
|
+
assert_equal 5, b.eval('x')
|
55
|
+
assert_equal ['b', 'x', 'y'], b.local_variables.sort
|
56
|
+
assert_equal 5, b[:x]
|
57
|
+
assert_equal 7, (b[:y] = 7)
|
58
|
+
assert_equal 7, y
|
59
|
+
assert_equal 'local-variable', b.defined?(:y)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Test the Binding methods in the of_caller context.
|
63
|
+
def test_binding_methods_with_of_caller
|
64
|
+
x = "foo"
|
65
|
+
y = 33
|
66
|
+
_target
|
67
|
+
assert_equal "FOO", x
|
68
|
+
assert_equal -33, y
|
69
|
+
end
|
70
|
+
|
71
|
+
# Target method for #test_binding_methods_with_of_caller.
|
72
|
+
def _target
|
73
|
+
Binding.of_caller do |b|
|
74
|
+
assert_equal "foo", b[:x]
|
75
|
+
assert_equal 33, b[:y]
|
76
|
+
assert_equal ['x', 'y'], b.local_variables.sort
|
77
|
+
assert_equal "foo!", b.eval('x + y.chr')
|
78
|
+
b[:x].upcase!
|
79
|
+
b[:y] *= -1
|
80
|
+
assert_equal "FOO", b[:x]
|
81
|
+
assert_equal -33, b[:y]
|
82
|
+
assert_equal 'local-variable', b.defined?(:y)
|
83
|
+
assert_equal nil, b.defined?(:foobar)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end # class TC_Binding
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'extensions/continuation'
|
3
|
+
|
4
|
+
class TC_Continuation < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# Test Continuation.create using the counter example from the documentation.
|
7
|
+
def test_counter
|
8
|
+
shadow_counter = 11
|
9
|
+
continuation, counter = Continuation.create(10) # (A)
|
10
|
+
shadow_counter -= 1
|
11
|
+
assert_equal(shadow_counter, counter)
|
12
|
+
continuation.call(counter - 1) if counter > 0 # goto (A) if counter > 0
|
13
|
+
assert_equal(0, counter)
|
14
|
+
assert_equal(shadow_counter, counter)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Test Continuation.create using the cc_inject example from the documentation.
|
18
|
+
def test_cc_inject
|
19
|
+
sum1_5 = [1,2,3,4,5].cc_inject { |acc, n| acc + n }
|
20
|
+
assert_equal(15, sum1_5)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Implement Array#cc_inject for the test_cc_inject method.
|
24
|
+
class ::Array
|
25
|
+
def cc_inject( value=nil )
|
26
|
+
copy = self.clone
|
27
|
+
cc, result, item = Continuation.create( value, nil )
|
28
|
+
next_item = copy.shift
|
29
|
+
if result and item
|
30
|
+
cc.call( yield(result, item), next_item )
|
31
|
+
elsif next_item
|
32
|
+
cc.call( next_item, result )
|
33
|
+
end
|
34
|
+
result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end # class TC_Continuation
|
metadata
CHANGED
@@ -3,21 +3,16 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: extensions
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2004-
|
8
|
-
summary: "'extensions' is a set of extensions to Ruby's built-in classes. It gathers
|
9
|
-
common idioms, useful additions, and aliases, complete with unit testing and
|
10
|
-
documentation, so they are suitable for production code."
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2004-10-04
|
8
|
+
summary: "'extensions' is a set of extensions to Ruby's built-in classes. It gathers common idioms, useful additions, and aliases, complete with unit testing and documentation, so they are suitable for production code."
|
11
9
|
require_paths:
|
12
10
|
- lib
|
13
11
|
author: Gavin Sinclair
|
14
12
|
email: gsinclair@soyabean.com.au
|
15
13
|
homepage: http://extensions.rubyforge.org
|
16
14
|
rubyforge_project: extensions
|
17
|
-
description: "'extensions' is a set of extensions to Ruby's built-in classes. It gathers
|
18
|
-
common idioms, useful additions, and aliases, complete with unit testing and
|
19
|
-
documentation, so they are suitable for production code. See
|
20
|
-
http://extensions.rubyforge.org for full documentation."
|
15
|
+
description: "'extensions' is a set of extensions to Ruby's built-in classes. It gathers common idioms, useful additions, and aliases, complete with unit testing and documentation, so they are suitable for production code. See http://extensions.rubyforge.org for full documentation."
|
21
16
|
autorequire:
|
22
17
|
default_executable: rbxtm
|
23
18
|
bindir: bin
|
@@ -33,6 +28,7 @@ platform: ruby
|
|
33
28
|
files:
|
34
29
|
- ChangeLog
|
35
30
|
- HISTORY
|
31
|
+
- InstalledFiles
|
36
32
|
- Rakefile
|
37
33
|
- README
|
38
34
|
- README.1st
|
@@ -44,7 +40,9 @@ files:
|
|
44
40
|
- lib/extensions
|
45
41
|
- lib/extensions/all.rb
|
46
42
|
- lib/extensions/array.rb
|
43
|
+
- lib/extensions/binding.rb
|
47
44
|
- lib/extensions/class.rb
|
45
|
+
- lib/extensions/continuation.rb
|
48
46
|
- lib/extensions/enumerable.rb
|
49
47
|
- lib/extensions/hash.rb
|
50
48
|
- lib/extensions/io.rb
|
@@ -56,7 +54,9 @@ files:
|
|
56
54
|
- lib/extensions/_base.rb
|
57
55
|
- lib/extensions/_template.rb
|
58
56
|
- "./test/tc_array.rb"
|
57
|
+
- "./test/tc_binding.rb"
|
59
58
|
- "./test/tc_class.rb"
|
59
|
+
- "./test/tc_continuation.rb"
|
60
60
|
- "./test/tc_enumerable.rb"
|
61
61
|
- "./test/tc_hash.rb"
|
62
62
|
- "./test/tc_io.rb"
|
@@ -67,14 +67,14 @@ files:
|
|
67
67
|
- "./test/tc_symbol.rb"
|
68
68
|
- "./test/TEST.rb"
|
69
69
|
- etc/checklist
|
70
|
-
- etc/doctools
|
71
|
-
- etc/release
|
72
70
|
- etc/website
|
73
71
|
- etc/website/index.html
|
74
72
|
- etc/website/upload.sh
|
75
73
|
test_files:
|
76
74
|
- test/tc_array.rb
|
75
|
+
- test/tc_binding.rb
|
77
76
|
- test/tc_class.rb
|
77
|
+
- test/tc_continuation.rb
|
78
78
|
- test/tc_enumerable.rb
|
79
79
|
- test/tc_hash.rb
|
80
80
|
- test/tc_io.rb
|