ruby_ext 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +64 -0
- data/lib/ruby_ext/array.rb +13 -0
- data/lib/ruby_ext/basic_object.rb +22 -0
- data/lib/ruby_ext/class.rb +11 -0
- data/lib/ruby_ext/declarative_cache.rb +85 -0
- data/lib/ruby_ext/deep_clone.rb +62 -0
- data/lib/ruby_ext/extra_blank_slate.rb +16 -0
- data/lib/ruby_ext/file.rb +20 -0
- data/lib/ruby_ext/hash.rb +15 -0
- data/lib/ruby_ext/kernel.rb +69 -0
- data/lib/ruby_ext/micelaneous.rb +14 -0
- data/lib/ruby_ext/module.rb +119 -0
- data/lib/ruby_ext/multiple_inheritance.rb +76 -0
- data/lib/ruby_ext/must.rb +192 -0
- data/lib/ruby_ext/not_defined.rb +2 -0
- data/lib/ruby_ext/object.rb +8 -0
- data/lib/ruby_ext/observable2.rb +23 -0
- data/lib/ruby_ext/open_constructor.rb +51 -0
- data/lib/ruby_ext/open_object.rb +157 -0
- data/lib/ruby_ext/prepare_arguments.rb +105 -0
- data/lib/ruby_ext/prototype_inheritance.rb +110 -0
- data/lib/ruby_ext/should.rb +166 -0
- data/lib/ruby_ext/string.rb +44 -0
- data/lib/ruby_ext/symbol.rb +21 -0
- data/lib/ruby_ext/synchronize.rb +24 -0
- data/lib/ruby_ext/tuple.rb +7 -0
- data/lib/ruby_ext.rb +50 -0
- data/lib/spec_ext.rb +10 -0
- data/readme.md +66 -0
- data/spec/_prototype_inheritance_spec.rb +190 -0
- data/spec/array_spec.rb +8 -0
- data/spec/declarative_cache_spec.rb +115 -0
- data/spec/deep_clone_spec.rb +37 -0
- data/spec/helper.rb +20 -0
- data/spec/kernel_spec/TheNamespace/ClassA.rb +7 -0
- data/spec/kernel_spec/another_class.rb +5 -0
- data/spec/kernel_spec/the_namespace/class_b.rb +11 -0
- data/spec/kernel_spec.rb +53 -0
- data/spec/module_spec.rb +160 -0
- data/spec/multiple_inheritance_spec.rb +131 -0
- data/spec/must_spec.rb +29 -0
- data/spec/observable2_spec.rb +42 -0
- data/spec/open_constructor_spec.rb +36 -0
- data/spec/open_object_spec.rb +29 -0
- data/spec/prepare_arguments_spec.rb +46 -0
- data/spec/should_spec.rb +24 -0
- data/spec/spec.opts +2 -0
- data/spec/synchronize_spec.rb +80 -0
- metadata +127 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
require "#{File.dirname __FILE__}/helper"
|
2
|
+
require "ruby_ext/synchronize"
|
3
|
+
|
4
|
+
describe "Synchronize" do
|
5
|
+
it "synchronize_method" do
|
6
|
+
class SAccount
|
7
|
+
attr_reader :from, :to
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
@from, @to = 0, 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def transfer
|
15
|
+
@from -= 1
|
16
|
+
@to += 1
|
17
|
+
end
|
18
|
+
synchronize_method :transfer
|
19
|
+
end
|
20
|
+
|
21
|
+
a, threads = SAccount.new, []
|
22
|
+
100.times do
|
23
|
+
t = Thread.new do
|
24
|
+
100.times{a.transfer}
|
25
|
+
end
|
26
|
+
threads << t
|
27
|
+
end
|
28
|
+
threads.each{|t| t.join}
|
29
|
+
|
30
|
+
a.from.should == -10_000
|
31
|
+
a.to.should == 10_000
|
32
|
+
end
|
33
|
+
|
34
|
+
it "synchronize_all_methods" do
|
35
|
+
class SAccount2
|
36
|
+
attr_reader :from, :to
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
super
|
40
|
+
@from, @to = 0, 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def transfer
|
44
|
+
@from -= 1
|
45
|
+
@to += 1
|
46
|
+
end
|
47
|
+
synchronize_all_methods
|
48
|
+
end
|
49
|
+
|
50
|
+
a, threads = SAccount2.new, []
|
51
|
+
100.times do
|
52
|
+
t = Thread.new do
|
53
|
+
100.times{a.transfer}
|
54
|
+
end
|
55
|
+
threads << t
|
56
|
+
end
|
57
|
+
threads.each{|t| t.join}
|
58
|
+
|
59
|
+
a.from.should == -10_000
|
60
|
+
a.to.should == 10_000
|
61
|
+
end
|
62
|
+
|
63
|
+
it "singleton" do
|
64
|
+
class SAccount3
|
65
|
+
class << self
|
66
|
+
def a; end
|
67
|
+
synchronize_method :a
|
68
|
+
end
|
69
|
+
end
|
70
|
+
SAccount3.a
|
71
|
+
end
|
72
|
+
|
73
|
+
it "shouldn't allow to synchronize twice" do
|
74
|
+
class SAccount4
|
75
|
+
def a; end
|
76
|
+
end
|
77
|
+
SAccount4.synchronize_method :a
|
78
|
+
lambda{SAccount4.synchronize_method :a}.should raise_error(/twice/)
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 6
|
10
|
+
version: 0.4.6
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alexey Petrushin
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-11 00:00:00 +04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: facets
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description:
|
36
|
+
email:
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- Rakefile
|
45
|
+
- readme.md
|
46
|
+
- lib/ruby_ext/array.rb
|
47
|
+
- lib/ruby_ext/basic_object.rb
|
48
|
+
- lib/ruby_ext/class.rb
|
49
|
+
- lib/ruby_ext/declarative_cache.rb
|
50
|
+
- lib/ruby_ext/deep_clone.rb
|
51
|
+
- lib/ruby_ext/extra_blank_slate.rb
|
52
|
+
- lib/ruby_ext/file.rb
|
53
|
+
- lib/ruby_ext/hash.rb
|
54
|
+
- lib/ruby_ext/kernel.rb
|
55
|
+
- lib/ruby_ext/micelaneous.rb
|
56
|
+
- lib/ruby_ext/module.rb
|
57
|
+
- lib/ruby_ext/multiple_inheritance.rb
|
58
|
+
- lib/ruby_ext/must.rb
|
59
|
+
- lib/ruby_ext/not_defined.rb
|
60
|
+
- lib/ruby_ext/object.rb
|
61
|
+
- lib/ruby_ext/observable2.rb
|
62
|
+
- lib/ruby_ext/open_constructor.rb
|
63
|
+
- lib/ruby_ext/open_object.rb
|
64
|
+
- lib/ruby_ext/prepare_arguments.rb
|
65
|
+
- lib/ruby_ext/prototype_inheritance.rb
|
66
|
+
- lib/ruby_ext/should.rb
|
67
|
+
- lib/ruby_ext/string.rb
|
68
|
+
- lib/ruby_ext/symbol.rb
|
69
|
+
- lib/ruby_ext/synchronize.rb
|
70
|
+
- lib/ruby_ext/tuple.rb
|
71
|
+
- lib/ruby_ext.rb
|
72
|
+
- lib/spec_ext.rb
|
73
|
+
- spec/_prototype_inheritance_spec.rb
|
74
|
+
- spec/array_spec.rb
|
75
|
+
- spec/declarative_cache_spec.rb
|
76
|
+
- spec/deep_clone_spec.rb
|
77
|
+
- spec/helper.rb
|
78
|
+
- spec/kernel_spec/another_class.rb
|
79
|
+
- spec/kernel_spec/the_namespace/class_b.rb
|
80
|
+
- spec/kernel_spec/TheNamespace/ClassA.rb
|
81
|
+
- spec/kernel_spec.rb
|
82
|
+
- spec/module_spec.rb
|
83
|
+
- spec/multiple_inheritance_spec.rb
|
84
|
+
- spec/must_spec.rb
|
85
|
+
- spec/observable2_spec.rb
|
86
|
+
- spec/open_constructor_spec.rb
|
87
|
+
- spec/open_object_spec.rb
|
88
|
+
- spec/prepare_arguments_spec.rb
|
89
|
+
- spec/should_spec.rb
|
90
|
+
- spec/spec.opts
|
91
|
+
- spec/synchronize_spec.rb
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://github.com/alexeypetrushin/ruby_ext
|
94
|
+
licenses: []
|
95
|
+
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.3.7
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: Ruby language extensions
|
126
|
+
test_files: []
|
127
|
+
|