forwardablex 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +9 -0
- data/README.md +5 -5
- data/lib/forwardablex.rb +5 -1
- data/lib/forwardablex/version.rb +1 -1
- data/test/spec_forwardablex.rb +23 -0
- metadata +3 -2
data/HISTORY.md
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# ForwardableX
|
2
2
|
|
3
|
-
|
3
|
+
ForwardableX is a Ruby library to extend forwardable.rb.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -49,15 +49,15 @@ class Forwarder
|
|
49
49
|
def m
|
50
50
|
"forwarded"
|
51
51
|
end
|
52
|
-
|
53
|
-
forward
|
52
|
+
end
|
53
|
+
forward :class, :m
|
54
54
|
end
|
55
55
|
Forwarder.new.m #=> "forwarded"
|
56
56
|
```
|
57
57
|
|
58
58
|
## Licence
|
59
59
|
|
60
|
-
|
60
|
+
ForwardableX is free software distributed under MIT licence.
|
61
61
|
|
62
62
|
## Contributing
|
63
63
|
|
data/lib/forwardablex.rb
CHANGED
@@ -38,7 +38,7 @@ require "forwardablex/version"
|
|
38
38
|
# "forwarded"
|
39
39
|
# end
|
40
40
|
# end
|
41
|
-
# forward
|
41
|
+
# forward :class, :m
|
42
42
|
# end
|
43
43
|
# Forwarder.new.m #=> "forwarded"
|
44
44
|
module ForwardableX
|
@@ -56,6 +56,10 @@ module ForwardableX
|
|
56
56
|
context = self.kind_of?(Module) ? self : self.singleton_class
|
57
57
|
context.instance_eval do
|
58
58
|
case receiver
|
59
|
+
when :class
|
60
|
+
define_method(name) do |*args, &b|
|
61
|
+
self.class.__send__(method, *args, &b)
|
62
|
+
end
|
59
63
|
when Symbol, String
|
60
64
|
define_method(name) do |*args, &b|
|
61
65
|
instance_variable_get(receiver).__send__(method, *args, &b)
|
data/lib/forwardablex/version.rb
CHANGED
data/test/spec_forwardablex.rb
CHANGED
@@ -87,6 +87,24 @@ singletonforwarder = Forwarder.new("singletonforwarder").tap do |obj|
|
|
87
87
|
obj.def_singleton_delegators Receiver.new, :m8, :m9
|
88
88
|
end
|
89
89
|
|
90
|
+
class ClassMethodForwarder
|
91
|
+
class << self
|
92
|
+
def m
|
93
|
+
"forwarded"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
forward :class, :m
|
98
|
+
end
|
99
|
+
|
100
|
+
class ClassMethodForwarderA < ClassMethodForwarder
|
101
|
+
class << self
|
102
|
+
def m
|
103
|
+
"forwarded to A"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
90
108
|
describe 'ForwardableX' do
|
91
109
|
[ XForwarder.new,
|
92
110
|
DefDelegatorForwarder.new,
|
@@ -115,4 +133,9 @@ describe 'ForwardableX' do
|
|
115
133
|
end
|
116
134
|
end
|
117
135
|
end
|
136
|
+
|
137
|
+
it 'should forward to class' do
|
138
|
+
ClassMethodForwarder.new.m.should == "forwarded"
|
139
|
+
ClassMethodForwarderA.new.m.should == "forwarded to A"
|
140
|
+
end
|
118
141
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forwardablex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bacon
|
@@ -68,6 +68,7 @@ extra_rdoc_files: []
|
|
68
68
|
files:
|
69
69
|
- .gitignore
|
70
70
|
- Gemfile
|
71
|
+
- HISTORY.md
|
71
72
|
- LICENSE.txt
|
72
73
|
- README.md
|
73
74
|
- Rakefile
|