reincarnation 0.1.0 → 0.1.1
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/.gitignore +3 -0
- data/README.markdown +64 -0
- data/VERSION +1 -1
- data/lib/reincarnation.rb +20 -2
- data/spec/included_spec.rb +46 -0
- data/spec/namespaced_spec.rb +51 -0
- data/spec/reincarnation_spec.rb +0 -51
- data/spec/spec.opts +1 -0
- metadata +11 -4
- data/README.rdoc +0 -17
data/.gitignore
CHANGED
data/README.markdown
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# reincarnation
|
2
|
+
|
3
|
+
monkey patch existing class and modules with the added comfort of "super".
|
4
|
+
|
5
|
+
example for classes:
|
6
|
+
|
7
|
+
require 'reincarnation'
|
8
|
+
|
9
|
+
class Abc
|
10
|
+
def foo
|
11
|
+
"foo"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Abc.reincarnate
|
16
|
+
|
17
|
+
class Abc
|
18
|
+
def foo
|
19
|
+
puts super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Abc.new.foo
|
24
|
+
|
25
|
+
example for modules:
|
26
|
+
|
27
|
+
require 'reincarnation'
|
28
|
+
|
29
|
+
module Boo
|
30
|
+
def bar
|
31
|
+
"bar"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Boo.reincarnate
|
36
|
+
|
37
|
+
module Boo
|
38
|
+
def bar
|
39
|
+
puts super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class BooTest
|
44
|
+
include Boo
|
45
|
+
end
|
46
|
+
|
47
|
+
BooTest.new.bar
|
48
|
+
|
49
|
+
## installation
|
50
|
+
gem install reincarnation
|
51
|
+
|
52
|
+
## note on patches/pull requests
|
53
|
+
|
54
|
+
* fork the project.
|
55
|
+
* make your feature addition or bug fix.
|
56
|
+
* add tests for it. this is important so i don't break it in a
|
57
|
+
future version unintentionally.
|
58
|
+
* commit, do not mess with rakefile, version, or history.
|
59
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself i can ignore when i pull)
|
60
|
+
* send me a pull request. bonus points for topic branches.
|
61
|
+
|
62
|
+
## copyright
|
63
|
+
|
64
|
+
copyright (c) 2010 françois wurmus. see license for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/reincarnation.rb
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
|
3
3
|
class Module
|
4
|
+
def included(base)
|
5
|
+
bases << base
|
6
|
+
end
|
7
|
+
|
8
|
+
def bases
|
9
|
+
@bases ||= []
|
10
|
+
end
|
11
|
+
|
12
|
+
def poke_bases(m)
|
13
|
+
bases.each do |b|
|
14
|
+
b.module_eval do
|
15
|
+
include(m)
|
16
|
+
poke_bases(m)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
4
21
|
def name_without_namespace
|
5
22
|
name.gsub(/.*::/, '')
|
6
23
|
end
|
@@ -11,8 +28,9 @@ class Module
|
|
11
28
|
|
12
29
|
def reincarnate
|
13
30
|
buried = bury
|
14
|
-
parent.const_set(name_without_namespace, Module.new)
|
15
|
-
|
31
|
+
reborn = parent.const_set(name_without_namespace, Module.new)
|
32
|
+
poke_bases(reborn)
|
33
|
+
reborn.module_eval { include buried }
|
16
34
|
end
|
17
35
|
end
|
18
36
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "an included module" do
|
4
|
+
module A
|
5
|
+
def foo
|
6
|
+
"foo"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module B; include A; end
|
11
|
+
module C; include B; end
|
12
|
+
module D; include B; end
|
13
|
+
|
14
|
+
it "should still be included after reincarnation" do
|
15
|
+
A.reincarnate
|
16
|
+
module A
|
17
|
+
def foo
|
18
|
+
super*2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class ATestB; include B; end
|
23
|
+
ATestB.new.foo.should == "foofoo"
|
24
|
+
|
25
|
+
class ATestC; include C; end
|
26
|
+
ATestC.new.foo.should == "foofoo"
|
27
|
+
|
28
|
+
class ATestD; include D; end
|
29
|
+
ATestD.new.foo.should == "foofoo"
|
30
|
+
|
31
|
+
A.reincarnate
|
32
|
+
module A
|
33
|
+
def foo
|
34
|
+
super + bar
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module B; def bar; "B"; end; end
|
39
|
+
module C; def bar; "C"; end; end
|
40
|
+
module D; def bar; "D"; end; end
|
41
|
+
|
42
|
+
ATestB.new.foo.should == "foofooB"
|
43
|
+
ATestC.new.foo.should == "foofooC"
|
44
|
+
ATestD.new.foo.should == "foofooD"
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "a namespaced class" do
|
4
|
+
module M
|
5
|
+
class A
|
6
|
+
def foo
|
7
|
+
"foo"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be reincarnable" do
|
13
|
+
M::A.reincarnate
|
14
|
+
module M
|
15
|
+
class A
|
16
|
+
def foo
|
17
|
+
super*3
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
M::A.new.foo.should == "foofoofoo"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "a namespaced module" do
|
27
|
+
module M
|
28
|
+
module B
|
29
|
+
def bar
|
30
|
+
"bar"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be reincarnable" do
|
36
|
+
M::B.reincarnate
|
37
|
+
module M
|
38
|
+
module B
|
39
|
+
def bar
|
40
|
+
super*3
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class BTest
|
46
|
+
include M::B
|
47
|
+
end
|
48
|
+
|
49
|
+
BTest.new.bar.should == "barbarbar"
|
50
|
+
end
|
51
|
+
end
|
data/spec/reincarnation_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
|
4
3
|
describe "a class" do
|
5
4
|
class A
|
6
5
|
def foo
|
@@ -42,53 +41,3 @@ describe "a module" do
|
|
42
41
|
BooTest.new.bar.should == "barbar"
|
43
42
|
end
|
44
43
|
end
|
45
|
-
|
46
|
-
describe "a namespaced class" do
|
47
|
-
module M
|
48
|
-
class A
|
49
|
-
def foo
|
50
|
-
"foo"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should be reincarnable" do
|
56
|
-
M::A.reincarnate
|
57
|
-
module M
|
58
|
-
class A
|
59
|
-
def foo
|
60
|
-
super*3
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
M::A.new.foo.should == "foofoofoo"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "a namespaced module" do
|
70
|
-
module M
|
71
|
-
module B
|
72
|
-
def bar
|
73
|
-
"bar"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should be reincarnable" do
|
79
|
-
M::B.reincarnate
|
80
|
-
module M
|
81
|
-
module B
|
82
|
-
def bar
|
83
|
-
super*3
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
class BTest
|
89
|
-
include M::B
|
90
|
-
end
|
91
|
-
|
92
|
-
BTest.new.bar.should == "barbarbar"
|
93
|
-
end
|
94
|
-
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reincarnation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Fran\xC3\xA7ois Wurmus"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-09 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,15 +30,20 @@ extensions: []
|
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
32
|
- LICENSE
|
33
|
-
- README.
|
33
|
+
- README.markdown
|
34
34
|
files:
|
35
35
|
- .document
|
36
36
|
- .gitignore
|
37
37
|
- LICENSE
|
38
|
-
- README.
|
38
|
+
- README.markdown
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
41
|
- lib/reincarnation.rb
|
42
|
+
- spec/included_spec.rb
|
43
|
+
- spec/namespaced_spec.rb
|
44
|
+
- spec/reincarnation_spec.rb
|
45
|
+
- spec/spec.opts
|
46
|
+
- spec/spec_helper.rb
|
42
47
|
has_rdoc: true
|
43
48
|
homepage: http://github.com/fronx/reincarnation
|
44
49
|
licenses: []
|
@@ -68,5 +73,7 @@ signing_key:
|
|
68
73
|
specification_version: 3
|
69
74
|
summary: reincarnation for classes and modules
|
70
75
|
test_files:
|
76
|
+
- spec/included_spec.rb
|
77
|
+
- spec/namespaced_spec.rb
|
71
78
|
- spec/reincarnation_spec.rb
|
72
79
|
- spec/spec_helper.rb
|
data/README.rdoc
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
= reincarnation
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Note on Patches/Pull Requests
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
-
* Send me a pull request. Bonus points for topic branches.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2010 François Wurmus. See LICENSE for details.
|