ov 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/ov.rb +29 -13
- data/lib/ov/ov_method.rb +3 -3
- data/lib/ov/version.rb +1 -1
- data/ov.gemspec +2 -2
- data/spec/override_spec.rb +42 -24
- data/spec/spec_helper.rb +3 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 680d9c554fc5e652b5a39ce3b8f5e032e61f0909
|
4
|
+
data.tar.gz: 02692a0a2e5f41156ef406813bccca36b4f2d0a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eef0b62ea689f296e39c79ffe803d6aaf75f0ff1ed039b2d8b6b50b24c526492cc59456db57a669999a3612fbd28340c0d575d1267ef7bd2edb8899b89a958b2
|
7
|
+
data.tar.gz: c47c21193d7bd5b66e87fa90f6d118886cfcfa69ff8e121d892db0bc2c51ea659d4c3ea88aaa5018e05b25c60897d22551e919edbdbc0bec1feb19083ed7a158
|
data/lib/ov.rb
CHANGED
@@ -79,15 +79,15 @@ module Ov
|
|
79
79
|
def self.included(base) # :nodoc:
|
80
80
|
base.extend(self)
|
81
81
|
base.class_eval do
|
82
|
-
class_variable_set(:@@
|
82
|
+
class_variable_set(:@@__overload_methods, OA.new) if !class_variable_defined?(:@@__overload_methods)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
87
|
-
send(:class_variable_get, :@@
|
86
|
+
def __overload_methods # :nodoc:
|
87
|
+
send(:class_variable_get, :@@__overload_methods)
|
88
88
|
end
|
89
89
|
|
90
|
-
private :
|
90
|
+
private :__overload_methods
|
91
91
|
##
|
92
92
|
# Create new method with +name+ and +types+
|
93
93
|
# When method called +block+ will be executed
|
@@ -105,7 +105,7 @@ module Ov
|
|
105
105
|
undef_method name
|
106
106
|
end
|
107
107
|
|
108
|
-
|
108
|
+
__overload_methods << OverrideMethod.new(name, types, self, block)
|
109
109
|
|
110
110
|
if !self.method_defined?(name)
|
111
111
|
self.instance_exec do
|
@@ -117,16 +117,10 @@ module Ov
|
|
117
117
|
|
118
118
|
self.send(message, name) do |*args, &block|
|
119
119
|
types = *args.map(&:class)
|
120
|
-
owner =
|
121
|
-
self
|
122
|
-
elsif self.respond_to?(:ancestors) && self == ancestors.first
|
123
|
-
self.singleton_class
|
124
|
-
else
|
125
|
-
self.class
|
126
|
-
end
|
120
|
+
owner = need_owner()
|
127
121
|
|
128
122
|
method = OverrideMethod.new(name, types, owner)
|
129
|
-
z = owner.send(:
|
123
|
+
z = owner.send(:__overload_methods).where(method)
|
130
124
|
|
131
125
|
if z.nil?
|
132
126
|
if included
|
@@ -141,6 +135,28 @@ module Ov
|
|
141
135
|
end
|
142
136
|
end
|
143
137
|
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# return all defined with +let+ methods.
|
141
|
+
#
|
142
|
+
def multimethods()
|
143
|
+
owner = need_owner()
|
144
|
+
owner.send(:__overload_methods).map do |method|
|
145
|
+
[method.name, method.types] if method.owner == owner
|
146
|
+
end.compact
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
private
|
151
|
+
def need_owner #:nodoc:
|
152
|
+
if self.class == Module
|
153
|
+
self
|
154
|
+
elsif self.respond_to?(:ancestors) && self == ancestors.first
|
155
|
+
self.singleton_class
|
156
|
+
else
|
157
|
+
self.class
|
158
|
+
end
|
159
|
+
end
|
144
160
|
end
|
145
161
|
|
146
162
|
|
data/lib/ov/ov_method.rb
CHANGED
@@ -8,7 +8,7 @@ module Ov
|
|
8
8
|
def initialize(name, types, owner, body = proc{})
|
9
9
|
@name, @types, @owner, @body = name, types, owner, body
|
10
10
|
@ancestors = owner.ancestors.find_all do |ancestor|
|
11
|
-
ancestor.method_defined?(:
|
11
|
+
ancestor.method_defined?(:__overload_methods) && ancestor.class == Class
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -19,7 +19,7 @@ module Ov
|
|
19
19
|
|
20
20
|
def eql0?(other) #:nodoc:
|
21
21
|
@ancestors.find{|a|
|
22
|
-
a.
|
22
|
+
a.__overload_methods.find{|m|
|
23
23
|
m.name == other.name && m.types == other.types
|
24
24
|
}
|
25
25
|
}
|
@@ -32,7 +32,7 @@ module Ov
|
|
32
32
|
|
33
33
|
def like0?(other) #:nodoc:
|
34
34
|
@ancestors.find{|a|
|
35
|
-
a.
|
35
|
+
a.__overload_methods.find{|m|
|
36
36
|
m.like?(other)
|
37
37
|
}
|
38
38
|
}
|
data/lib/ov/version.rb
CHANGED
data/ov.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Ov::VERSION
|
9
9
|
spec.authors = ["fntzr"]
|
10
10
|
spec.email = ["fantazuor@gmail.com"]
|
11
|
-
spec.description = %q{write
|
12
|
-
spec.summary = %q{ov gem provides hacks for write
|
11
|
+
spec.description = %q{write overloaded methods for fun :)}
|
12
|
+
spec.summary = %q{ov gem provides hacks for write multimemethods in Ruby.}
|
13
13
|
spec.homepage = "https://github.com/fntzr/ov"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/spec/override_spec.rb
CHANGED
@@ -14,30 +14,36 @@ describe Ov do
|
|
14
14
|
|
15
15
|
it "return array" do
|
16
16
|
result = test.my_instance_method(["foo", "bar"], "baz")
|
17
|
-
result.
|
17
|
+
expect(result).to eq(["foo", "bar", "baz"])
|
18
18
|
end
|
19
19
|
|
20
20
|
it "return string" do
|
21
21
|
result = test.my_instance_method("baz")
|
22
|
-
result.
|
22
|
+
expect(result).to eq "baz"
|
23
23
|
end
|
24
24
|
|
25
|
-
it "return
|
25
|
+
it "return overload method" do
|
26
26
|
result = test.my_instance_method(1)
|
27
|
-
result.
|
27
|
+
expect(result).to eq ["bar"]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "return all let methods" do
|
31
|
+
expect(test.multimethods.size).to eq(3)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
32
|
-
context "
|
36
|
+
context "overload initialize method" do
|
33
37
|
it "return new instance with #this method" do
|
34
38
|
test = TestInitialize.new("bar")
|
35
|
-
test.arg.
|
36
|
-
test.class.
|
39
|
+
expect(test.arg).to eq "barfoo"
|
40
|
+
expect(test.class).to eq TestInitialize
|
37
41
|
|
38
42
|
test0 = TestInitialize.new(1)
|
39
|
-
test0.arg.
|
40
|
-
test0.class.
|
43
|
+
expect(test0.arg).to eq 100
|
44
|
+
expect(test0.class).to eq TestInitialize
|
45
|
+
|
46
|
+
expect(test.multimethods.size).to eq(2)
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
@@ -52,11 +58,14 @@ describe Ov do
|
|
52
58
|
let(:test){Test0.new}
|
53
59
|
it "should call parent method" do
|
54
60
|
result = test.my_instance_method(["foo", "bar"], "baz")
|
55
|
-
result.
|
61
|
+
expect(result).to eq ["foo", "bar", "baz"]
|
56
62
|
end
|
57
63
|
it "should call own method" do
|
58
64
|
result = test.my_instance_method("baz")
|
59
|
-
result.
|
65
|
+
expect(result).to eq "foo"
|
66
|
+
end
|
67
|
+
it "should return multimethods" do
|
68
|
+
expect(test.multimethods.size).to eq(1)
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
@@ -65,16 +74,16 @@ describe Ov do
|
|
65
74
|
let(:test) {TestWithoutArguments.new}
|
66
75
|
it do
|
67
76
|
result = test.my_instance_method
|
68
|
-
result.
|
77
|
+
expect(result).to eq "foo"
|
69
78
|
end
|
70
79
|
end
|
71
80
|
|
72
81
|
context "call with Any argument" do
|
73
82
|
let(:test) {TestAny.new}
|
74
83
|
it do
|
75
|
-
test.my_instance_method(1).
|
76
|
-
test.my_instance_method("foo").
|
77
|
-
test.my_instance_method(:foo).
|
84
|
+
expect(test.my_instance_method(1)).to eq 1
|
85
|
+
expect(test.my_instance_method("foo")).to eq "foo"
|
86
|
+
expect(test.my_instance_method(:foo)).to eq :foo
|
78
87
|
end
|
79
88
|
|
80
89
|
it "exception when many arguments or without arguments" do
|
@@ -89,17 +98,21 @@ describe Ov do
|
|
89
98
|
|
90
99
|
it "return array" do
|
91
100
|
result = test.my_instance_method(["foo", "bar"], "baz")
|
92
|
-
result.
|
101
|
+
expect(result).to eq ["foo", "bar", "baz"]
|
93
102
|
end
|
94
103
|
|
95
104
|
it "return string" do
|
96
105
|
result = test.my_instance_method("baz")
|
97
|
-
result.
|
106
|
+
expect(result).to eq "baz"
|
98
107
|
end
|
99
108
|
|
100
|
-
it "return
|
109
|
+
it "return overload method" do
|
101
110
|
result = test.my_instance_method(1)
|
102
|
-
result.
|
111
|
+
expect(result).to eq ["bar"]
|
112
|
+
end
|
113
|
+
|
114
|
+
it "multimethods" do
|
115
|
+
expect(test.multimethods.size).to eq(3)
|
103
116
|
end
|
104
117
|
end
|
105
118
|
end
|
@@ -111,27 +124,32 @@ describe Ov do
|
|
111
124
|
|
112
125
|
it "return array" do
|
113
126
|
result = test.my_instance_method(["foo", "bar"], "baz")
|
114
|
-
result.
|
127
|
+
expect(result).to eq ["foo", "bar", "baz"]
|
115
128
|
end
|
116
129
|
|
117
130
|
it "return string" do
|
118
131
|
result = test.my_instance_method("baz")
|
119
|
-
result.
|
132
|
+
expect(result).to eq "baz"
|
120
133
|
end
|
121
134
|
|
122
|
-
it "return
|
135
|
+
it "return overload method" do
|
123
136
|
result = test.my_instance_method(1)
|
124
|
-
result.
|
137
|
+
expect(result).to eq ["bar"]
|
125
138
|
end
|
126
139
|
|
127
140
|
it "instance return string" do
|
128
141
|
result = test_ins.my_instance_method("baz")
|
129
|
-
result.
|
142
|
+
expect(result).to eq "baz"
|
130
143
|
end
|
131
144
|
|
132
145
|
it "exception when not defined" do
|
133
146
|
expect{ test_ins.my_instance_method(1,2,3)}.to raise_error(Ov::NotImplementError)
|
134
147
|
end
|
148
|
+
|
149
|
+
it "multimethods" do
|
150
|
+
expect(test.multimethods.size).to eq(3)
|
151
|
+
expect(test_ins.multimethods.size).to eq(1)
|
152
|
+
end
|
135
153
|
end
|
136
154
|
end
|
137
155
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fntzr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.14.0
|
55
|
-
description: write
|
55
|
+
description: write overloaded methods for fun :)
|
56
56
|
email:
|
57
57
|
- fantazuor@gmail.com
|
58
58
|
executables: []
|
@@ -103,7 +103,7 @@ rubyforge_project:
|
|
103
103
|
rubygems_version: 2.2.2
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
|
-
summary: ov gem provides hacks for write
|
106
|
+
summary: ov gem provides hacks for write multimemethods in Ruby.
|
107
107
|
test_files:
|
108
108
|
- spec/fixtures/fixture_classes.rb
|
109
109
|
- spec/override_spec.rb
|