bzproxies 0.1.6 → 0.1.7
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/lib/bzproxies/base.rb +3 -3
- data/lib/bzproxies/core_ext.rb +3 -3
- data/lib/bzproxies/version.rb +1 -1
- data/spec/base_spec.rb +27 -0
- metadata +1 -1
data/lib/bzproxies/base.rb
CHANGED
@@ -30,7 +30,7 @@ module Proxies
|
|
30
30
|
|
31
31
|
def respond_to? meth, hidden = false
|
32
32
|
metaclass = class << self; self; end
|
33
|
-
(metaclass.method_defined? meth) || (
|
33
|
+
(metaclass.method_defined? meth) || (__getobj__.respond_to? meth, hidden)
|
34
34
|
end
|
35
35
|
|
36
36
|
def eql? any
|
@@ -40,7 +40,7 @@ module Proxies
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def == any
|
43
|
-
(any.respond_to? :proxy?) ?
|
43
|
+
(any.respond_to? :proxy?) ? __getobj__ == any.__getobj__ : __getobj__ == any
|
44
44
|
end
|
45
45
|
|
46
46
|
def initialize *args
|
@@ -57,7 +57,7 @@ module Proxies
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def __getobj__
|
60
|
-
|
60
|
+
self.target
|
61
61
|
end
|
62
62
|
|
63
63
|
|
data/lib/bzproxies/core_ext.rb
CHANGED
@@ -7,20 +7,20 @@ end
|
|
7
7
|
class NilClass
|
8
8
|
alias old_equality ==
|
9
9
|
def == any
|
10
|
-
(any.respond_to? :
|
10
|
+
(any.respond_to? :__getobj__) ? old_equality(any.__getobj__) : old_equality(any)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
class TrueClass
|
15
15
|
alias old_equality ==
|
16
16
|
def == any
|
17
|
-
(any.respond_to? :
|
17
|
+
(any.respond_to? :__getobj__) ? old_equality(any.__getobj__) : old_equality(any)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
class FalseClass
|
22
22
|
alias old_equality ==
|
23
23
|
def == any
|
24
|
-
(any.respond_to? :
|
24
|
+
(any.respond_to? :__getobj__) ? old_equality(any.__getobj__) : old_equality(any)
|
25
25
|
end
|
26
26
|
end
|
data/lib/bzproxies/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -93,6 +93,33 @@ describe Proxies::Base do
|
|
93
93
|
t = Tester.new({:test => {"tatata" => 1}})
|
94
94
|
t["tatata"].should == 1
|
95
95
|
end
|
96
|
+
|
97
|
+
it "should correctly use __getobj__ with equality and other operations" do
|
98
|
+
["string", 1, false, nil].each do |val|
|
99
|
+
a = val
|
100
|
+
test1 = Tester.new :test => a
|
101
|
+
test2 = Tester.new :test => a
|
102
|
+
test3 = Tester.new :test => val
|
103
|
+
|
104
|
+
(a == test1).should be_true
|
105
|
+
(a == test3).should be_true
|
106
|
+
(test1 == a).should be_true
|
107
|
+
(test3 == a).should be_true
|
108
|
+
|
109
|
+
a.should_not be_eql test1
|
110
|
+
(test1.eql? a).should be_false
|
111
|
+
|
112
|
+
(test1 == test2).should be_true
|
113
|
+
(test2 == test1).should be_true
|
114
|
+
(test1 == test3).should be_true
|
115
|
+
(test3 == test1).should be_true
|
116
|
+
|
117
|
+
(test1.eql? test2).should be_true
|
118
|
+
(test2.eql? test1).should be_true
|
119
|
+
(test1.eql? test3).should be_true
|
120
|
+
(test3.eql? test1).should be_true
|
121
|
+
end
|
122
|
+
end
|
96
123
|
|
97
124
|
|
98
125
|
|