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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2fb8e560e4e2f7ebed892f926df1f81238781f3
4
- data.tar.gz: 82cba6f07a2aee4fc5e0b959f655559bcb9134e6
3
+ metadata.gz: 680d9c554fc5e652b5a39ce3b8f5e032e61f0909
4
+ data.tar.gz: 02692a0a2e5f41156ef406813bccca36b4f2d0a9
5
5
  SHA512:
6
- metadata.gz: b5fd66e11d9c6d638888c6e5a83e65f7f01d8ded65091f626c58eb6bb22aa6bba2d0152d21fa1cd838d8c06b5d91ec7982bd13255d697e82ee73693199cb7172
7
- data.tar.gz: 19ba949b79b683f21dae23c05fd3162372b87fb955a49586d44953870578fe3bb96c4714b41b1fd8a6b205fbaeafff033fb9ab4540030213c1ecb8b64e5a0414
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(:@@__overridable_methods, OA.new) if !class_variable_defined?(:@@__overridable_methods)
82
+ class_variable_set(:@@__overload_methods, OA.new) if !class_variable_defined?(:@@__overload_methods)
83
83
  end
84
84
  end
85
85
 
86
- def __overridable_methods # :nodoc:
87
- send(:class_variable_get, :@@__overridable_methods)
86
+ def __overload_methods # :nodoc:
87
+ send(:class_variable_get, :@@__overload_methods)
88
88
  end
89
89
 
90
- private :__overridable_methods
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
- __overridable_methods << OverrideMethod.new(name, types, self, block)
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 = if self.class == Module
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(:__overridable_methods).where(method)
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
 
@@ -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?(:__overridable_methods) && ancestor.class == Class
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.__overridable_methods.find{|m|
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.__overridable_methods.find{|m|
35
+ a.__overload_methods.find{|m|
36
36
  m.like?(other)
37
37
  }
38
38
  }
@@ -1,3 +1,3 @@
1
1
  module Ov
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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 overridable methods for fun :)}
12
- spec.summary = %q{ov gem provides hacks for write polymorphic methods in Ruby.}
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
 
@@ -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.should eq ["foo", "bar", "baz"]
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.should eq "baz"
22
+ expect(result).to eq "baz"
23
23
  end
24
24
 
25
- it "return overridable method" do
25
+ it "return overload method" do
26
26
  result = test.my_instance_method(1)
27
- result.should eq ["bar"]
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 "override initialize method" do
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.should eq "barfoo"
36
- test.class.should eq TestInitialize
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.should eq 100
40
- test0.class.should eq TestInitialize
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.should eq ["foo", "bar", "baz"]
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.should eq "foo"
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.should eq "foo"
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).should eq 1
76
- test.my_instance_method("foo").should eq "foo"
77
- test.my_instance_method(:foo).should eq :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.should eq ["foo", "bar", "baz"]
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.should eq "baz"
106
+ expect(result).to eq "baz"
98
107
  end
99
108
 
100
- it "return overridable method" do
109
+ it "return overload method" do
101
110
  result = test.my_instance_method(1)
102
- result.should eq ["bar"]
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.should eq ["foo", "bar", "baz"]
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.should eq "baz"
132
+ expect(result).to eq "baz"
120
133
  end
121
134
 
122
- it "return overridable method" do
135
+ it "return overload method" do
123
136
  result = test.my_instance_method(1)
124
- result.should eq ["bar"]
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.should eq "baz"
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
@@ -1,3 +1,6 @@
1
1
  require 'ov'
2
2
  require 'fixtures/fixture_classes'
3
3
 
4
+ RSpec.configure do |config|
5
+ config.color = true
6
+ end
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.3
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-09-13 00:00:00.000000000 Z
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 overridable methods for fun :)
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 polymorphic methods in Ruby.
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