object2module 0.3.0-i386-mingw32 → 0.4.0-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- # Rakefile added by John Mair (banisterfiend)
1
+ # Rakefile added by John Mair (banisterfiend)
2
2
 
3
3
  require 'rake/gempackagetask'
4
+ require 'rake/rdoctask'
4
5
  require 'rake/clean'
5
- require 'lib/object2module/version.rb'
6
+ require './lib/object2module/version.rb'
6
7
 
7
8
  dlext = Config::CONFIG['DLEXT']
9
+ direc = File.dirname(__FILE__)
8
10
 
9
11
  CLEAN.include("ext/**/*.#{dlext}", "ext/**/.log", "ext/**/.o", "ext/**/*~", "ext/**/*#*", "ext/**/.obj", "ext/**/.def", "ext/**/.pdb")
10
12
  CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o", "doc/**")
@@ -24,30 +26,48 @@ def apply_spec_defaults(s)
24
26
  end
25
27
 
26
28
 
27
- # common tasks
28
- task :compile => :clean
29
-
30
- spec = Gem::Specification.new do |s|
31
- apply_spec_defaults(s)
32
- s.platform = 'i386-mingw32'
33
- s.files = ["Rakefile", "README", "LICENSE",
34
- "lib/object2module.rb", "lib/1.8/object2module.#{dlext}",
35
- "lib/1.9/object2module.#{dlext}", "lib/object2module/version.rb", "test/test_object2module.rb"]
29
+ task :test do
30
+ sh "bacon -k #{direc}/test/test.rb"
36
31
  end
37
32
 
33
+ [:mingw32, :mswin32].each do |v|
34
+ task v do
35
+ spec = Gem::Specification.new do |s|
36
+ apply_spec_defaults(s)
37
+ s.platform = "i386-#{v}"
38
+ s.files = FileList["Rakefile", "README", "LICENSE",
39
+ "lib/object2module.rb", "lib/1.8/object2module.#{dlext}",
40
+ "lib/1.9/object2module.#{dlext}", "lib/object2module/version.rb", "test/*.rb"].to_a
41
+ end
42
+
43
+ Rake::GemPackageTask.new(spec) do |pkg|
44
+ pkg.need_zip = false
45
+ pkg.need_tar = false
46
+ end
38
47
 
48
+ Rake::Task[:gem].invoke
49
+ end
50
+ end
39
51
 
52
+ task :ruby do
53
+ spec = Gem::Specification.new do |s|
54
+ apply_spec_defaults(s)
55
+ s.platform = Gem::Platform::RUBY
56
+ s.files = FileList["Rakefile", "README", "LICENSE",
57
+ "lib/object2module.rb","lib/object2module/version.rb",
58
+ "test/*.rb", "ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
59
+ s.extensions = ["ext/object2module/extconf.rb"]
60
+ end
40
61
 
62
+ Rake::GemPackageTask.new(spec) do |pkg|
63
+ pkg.need_zip = false
64
+ pkg.need_tar = false
65
+ end
41
66
 
42
- # spec = Gem::Specification.new do |s|
43
- # apply_spec_defaults(s)
44
- # s.platform = Gem::Platform::RUBY
45
- # s.extensions = FileList["ext/**/extconf.rb"]
46
- # s.files = ["Rakefile", "README", "LICENSE", "lib/object2module.rb", "lib/object2module/version.rb", "test/test_object2module.rb"] +
47
- # FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
48
- # end
67
+ Rake::Task[:gem].invoke
68
+ end
49
69
 
50
- Rake::GemPackageTask.new(spec) do |pkg|
51
- pkg.need_zip = false
52
- pkg.need_tar = false
70
+ Rake::RDocTask.new do |rd|
71
+ rd.main = "README.rdoc"
72
+ rd.rdoc_files.include("README.rdoc", "lib/object2module.rb")
53
73
  end
Binary file
Binary file
@@ -1,3 +1,3 @@
1
1
  module Object2module
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/object2module.rb CHANGED
@@ -15,79 +15,75 @@ rescue LoadError => e
15
15
  require "#{direc}/object2module.#{dlext}"
16
16
  end
17
17
 
18
+ module Kernel
18
19
 
19
- # call-seq:
20
- # obj.gen_extend(other, ...) => obj
20
+ # define a `singleton_class` method for the 1.8 kids
21
+ # @return [Class] The singleton class of the receiver
22
+ def singleton_class
23
+ class << self; self; end
24
+ end if !respond_to?(:singleton_class)
25
+ end
21
26
 
22
- # Adds to _obj_ the instance methods from each object given as a
23
- # parameter.
24
-
25
- # class C
26
- # def hello
27
- # "Hello from C.\n"
28
- # end
29
- # end
30
-
31
- # class Klass
32
- # def hello
33
- # "Hello from Klass.\n"
34
- # end
35
- # end
36
-
37
- # k = Klass.new
38
- # k.hello #=> "Hello from Klass.\n"
39
- # k.gen_extend(C) #=> #<Klass:0x401b3bc8>
40
- # k.hello #=> "Hello from C.\n"
41
27
  class Object
42
- def gen_extend(*objs)
43
- raise ArgumentError, "wrong number of arguments (0 for 1)" if objs.empty?
28
+ def __gen_extend_or_include__(extend_or_include, *objs) #:nodoc:
29
+ raise ArgumentError, "wrong number of arguments (at least 1)" if objs.empty?
44
30
 
45
- objs.each { |o|
46
- begin
47
- mod = o.__to_module__
48
- extend(mod)
49
- ensure
50
- mod.__reset_tbls__ if mod != o &&o != Object && o != Class && o != Module
51
- end
31
+ objs.each { |mod|
32
+ send(extend_or_include, mod)
52
33
  }
53
34
 
54
35
  self
55
36
  end
56
- end
57
37
 
38
+ # Adds to the singleton class of receiver the instance methods from each object given as a
39
+ # parameter.
40
+ #
41
+ # @param [Array] objs The array of objects to `gen_extend`
42
+ # @return [Object] The receiver
43
+ # @example
44
+ # class C
45
+ # def hello
46
+ # "Hello from C.\n"
47
+ # end
48
+ # end
49
+ #
50
+ # class Klass
51
+ # def hello
52
+ # "Hello from Klass.\n"
53
+ # end
54
+ # end
55
+ #
56
+ # k = Klass.new
57
+ # k.hello #=> "Hello from Klass.\n"
58
+ # k.gen_extend(C) #=> #<Klass:0x401b3bc8>
59
+ # k.hello #=> "Hello from C.\n"
60
+ def gen_extend(*objs)
61
+ singleton_class.__gen_extend_or_include__(:gen_include_one, *objs)
62
+ end
63
+ end
58
64
 
59
- # call-seq:
60
- # gen_include(other, ...) => self
61
-
62
- # Adds to the implied receiver the instance methods from each object given as a
63
- # parameter.
64
-
65
- # class C
66
- # def hello
67
- # "Hello from C.\n"
68
- # end
69
- # end
70
-
71
- # class Klass
72
- # gen_include(C)
73
- # end
74
-
75
- # k = Klass.new
76
- # k.hello #=> "Hello from C.\n"
77
65
  class Module
66
+
67
+ # Adds to the implied receiver the instance methods from each object given as a
68
+ # parameter.
69
+ #
70
+ # @param [Array] objs The array of objects to `gen_include`
71
+ # @return [Object] The receiver
72
+ # @example
73
+ # class C
74
+ # def hello
75
+ # "Hello from C.\n"
76
+ # end
77
+ # end
78
+ #
79
+ # class Klass
80
+ # gen_include(C)
81
+ # end
82
+ #
83
+ # k = Klass.new
84
+ # k.hello #=> "Hello from C.\n"
78
85
  def gen_include(*objs)
79
- raise ArgumentError, "wrong number of arguments (0 for 1)" if objs.empty?
80
-
81
- objs.each { |o|
82
- begin
83
- mod = o.__to_module__
84
- include(mod)
85
- ensure
86
- mod.__reset_tbls__ if mod != o && o != Object && o != Class && o != Module
87
- end
88
- }
89
-
90
- self
86
+ __gen_extend_or_include__(:gen_include_one, *objs)
91
87
  end
92
88
  end
93
89
 
data/test/test.rb ADDED
@@ -0,0 +1,165 @@
1
+ direc = File.dirname(__FILE__)
2
+ require 'rubygems'
3
+ require 'bacon'
4
+ require "#{direc}/../lib/object2module"
5
+
6
+
7
+ class Module
8
+ public :include, :remove_const
9
+ end
10
+
11
+ describe Object2module do
12
+ before do
13
+ class A
14
+ def a
15
+ :a
16
+ end
17
+ end
18
+
19
+ class B
20
+ def b
21
+ :b
22
+ end
23
+ end
24
+
25
+ module M
26
+ def m
27
+ :m
28
+ end
29
+ end
30
+
31
+ O = Object.new
32
+ class << O
33
+ def o
34
+ :o
35
+ end
36
+ end
37
+
38
+ C = Class.new
39
+ end
40
+
41
+ after do
42
+ Object.remove_const(:A)
43
+ Object.remove_const(:B)
44
+ Object.remove_const(:C)
45
+ Object.remove_const(:M)
46
+ Object.remove_const(:O)
47
+ end
48
+
49
+ describe 'gen_include' do
50
+ it 'includes a module' do
51
+ C.gen_include M
52
+ C.new.m.should == :m
53
+ end
54
+
55
+ it 'includes a class' do
56
+ C.gen_include A
57
+ C.new.a.should == :a
58
+ end
59
+
60
+ it 'includes an object' do
61
+ C.gen_include O
62
+ C.new.o.should == :o
63
+ end
64
+
65
+ it 'includes a class that includes a class' do
66
+ A.gen_include B
67
+ C.gen_include A
68
+ C.new.b.should == :b
69
+ C.new.a.should == :a
70
+ end
71
+
72
+ it 'includes an object that includes a class that includes a class' do
73
+ A.gen_include B
74
+ O.gen_extend A
75
+ C.gen_include O
76
+ C.new.o.should == :o
77
+ C.new.a.should == :a
78
+ C.new.b.should == :b
79
+ end
80
+
81
+ it 'includes an object that includes an object' do
82
+ n = Object.new
83
+ class << n
84
+ def n
85
+ :n
86
+ end
87
+ end
88
+
89
+ l = Object.new
90
+ class << l
91
+ def l
92
+ :l
93
+ end
94
+ self
95
+ end.gen_include n
96
+
97
+ C.gen_include l
98
+ C.new.l.should == :l
99
+ C.new.n.should == :n
100
+ end
101
+ end
102
+
103
+ describe 'gen_extend' do
104
+ it 'extends a module' do
105
+ O.gen_extend M
106
+ O.m.should == :m
107
+ end
108
+
109
+ it 'extends a class' do
110
+ O.gen_extend A
111
+ O.a.should == :a
112
+ end
113
+
114
+ it 'extends an object' do
115
+ n = Object.new
116
+ class << n
117
+ def n
118
+ :n
119
+ end
120
+ end
121
+ O.gen_extend n
122
+ O.n.should == :n
123
+ end
124
+
125
+ it 'extends a class that includes a class' do
126
+ A.gen_include B
127
+ O.gen_extend A
128
+ O.b.should == :b
129
+ O.a.should == :a
130
+ end
131
+
132
+ it 'extends an object that includes a class that includes a class' do
133
+ A.gen_include B
134
+ C.gen_include A
135
+ O.gen_extend C
136
+ O.o.should == :o
137
+ O.a.should == :a
138
+ O.b.should == :b
139
+ end
140
+
141
+ it 'extends an object that extends an object' do
142
+ n = Object.new
143
+ class << n
144
+ def n
145
+ :n
146
+ end
147
+ end
148
+
149
+ l = Object.new
150
+ class << l
151
+ def l
152
+ :l
153
+ end
154
+ self
155
+ end
156
+
157
+ l.gen_extend n
158
+
159
+ O.gen_extend l
160
+ O.l.should == :l
161
+ O.n.should == :n
162
+ end
163
+ end
164
+ end
165
+
@@ -0,0 +1,6 @@
1
+ require '../lib/object2module'
2
+
3
+ 80_000.times {
4
+ Object.new.gen_extend Object.new, Module.new, Class.new
5
+ Class.new.gen_include Object.new, Module.new, Class.new
6
+ }
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object2module
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 3
7
+ - 4
9
8
  - 0
10
- version: 0.3.0
9
+ version: 0.4.0
11
10
  platform: i386-mingw32
12
11
  authors:
13
12
  - John Mair (banisterfiend)
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-07-29 00:00:00 +12:00
17
+ date: 2010-10-31 00:00:00 +13:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -35,7 +34,8 @@ files:
35
34
  - lib/1.8/object2module.so
36
35
  - lib/1.9/object2module.so
37
36
  - lib/object2module/version.rb
38
- - test/test_object2module.rb
37
+ - test/test.rb
38
+ - test/test_stress.rb
39
39
  has_rdoc: true
40
40
  homepage: http://banisterfiend.wordpress.com
41
41
  licenses: []
@@ -50,7 +50,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- hash: 3
54
53
  segments:
55
54
  - 0
56
55
  version: "0"
@@ -59,7 +58,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
58
  requirements:
60
59
  - - ">="
61
60
  - !ruby/object:Gem::Version
62
- hash: 3
63
61
  segments:
64
62
  - 0
65
63
  version: "0"
@@ -1,147 +0,0 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require 'test/unit'
4
- require "#{direc}/../lib/object2module"
5
-
6
- module M
7
- def m
8
- "m"
9
- end
10
- end
11
-
12
- class A
13
- include M
14
-
15
- def a
16
- "a"
17
- end
18
- end
19
-
20
- class B < A
21
- def b
22
- "b"
23
- end
24
- end
25
-
26
- class C < B
27
- def c
28
- "c"
29
- end
30
- end
31
-
32
- # stand-alone class
33
- class K
34
- def k
35
- "k"
36
- end
37
- end
38
-
39
- # another stand-alone class
40
- class J
41
- def j
42
- "j"
43
- end
44
- end
45
-
46
- class Object2ModuleTest < Test::Unit::TestCase
47
- def test_class_to_module
48
- assert_instance_of(Module, C.__to_module__)
49
- end
50
-
51
- def test_class_heirarchy
52
- c = C.__to_module__
53
-
54
- h = c.ancestors
55
- assert_equal(B, h[1])
56
- assert_equal(A, h[2])
57
- assert_equal(M, h[3])
58
- end
59
-
60
- def test_class_extend
61
- o = Object.new
62
- assert_equal(o, o.gen_extend(C))
63
- end
64
-
65
- def test_class_extended_methods
66
- h = C.__to_module__
67
- o = Object.new
68
- o.extend(h)
69
- assert_equal("a", o.a)
70
- assert_equal("b", o.b)
71
- assert_equal("c", o.c)
72
- assert_equal("m", o.m)
73
- end
74
-
75
- def test_object_to_module
76
- o = C.new
77
- assert_instance_of(Module, o.__to_module__)
78
- end
79
-
80
- def test_object_heirarchy
81
- o = C.new
82
- h = o.__to_module__.ancestors
83
- assert_equal(C, h[1])
84
- assert_equal(B, h[2])
85
- assert_equal(A, h[3])
86
- assert_equal(M, h[4])
87
- end
88
-
89
- def test_object_extend
90
- h = C.__to_module__
91
- o = Object.new
92
- assert_equal(o, o.extend(h))
93
- end
94
-
95
- def test_object_extended_methods
96
- o = C.new
97
- h = o.__to_module__
98
- l = Object.new
99
- l.extend(h)
100
- assert_equal("a", l.a)
101
- assert_equal("b", l.b)
102
- assert_equal("c", l.c)
103
- assert_equal("m", l.m)
104
- end
105
-
106
- def test_gen_extend
107
- o = Object.new
108
- o.gen_extend(C)
109
- assert_equal("a", o.a)
110
- assert_equal("b", o.b)
111
- assert_equal("c", o.c)
112
- assert_equal("m", o.m)
113
- end
114
-
115
- def test_gen_include
116
- k = Class.new
117
- k.gen_include(C)
118
- o = k.new
119
- assert_equal("a", o.a)
120
- assert_equal("b", o.b)
121
- assert_equal("c", o.c)
122
- assert_equal("m", o.m)
123
- end
124
-
125
- def test_gen_extend_multi
126
- o = Object.new
127
- o.gen_extend(C, K, J)
128
- assert_equal("a", o.a)
129
- assert_equal("b", o.b)
130
- assert_equal("c", o.c)
131
- assert_equal("m", o.m)
132
- assert_equal("k", o.k)
133
- assert_equal("j", o.j)
134
- end
135
-
136
- def test_gen_include_multi
137
- k = Class.new
138
- k.gen_include(C, K, J)
139
- o = k.new
140
- assert_equal("a", o.a)
141
- assert_equal("b", o.b)
142
- assert_equal("c", o.c)
143
- assert_equal("m", o.m)
144
- assert_equal("k", o.k)
145
- assert_equal("j", o.j)
146
- end
147
- end