Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Index: lib/mocha/module_method.rb
===================================================================
--- lib/mocha/module_method.rb  (revision 334)
+++ lib/mocha/module_method.rb  (working copy)
@@ -5,11 +5,9 @@
   class ModuleMethod < ClassMethod
 
     def method_exists?(method)
-      existing_methods = []
-      existing_methods += stubbee.public_methods(false)
-      existing_methods += stubbee.protected_methods(false)
-      existing_methods += stubbee.private_methods(false)
-      existing_methods.any? { |m| m.to_s == method.to_s }
+      stubbee.public_methods(false).include?(method.to_s) ||
+      stubbee.protected_methods(false).include?(method.to_s) ||
+      stubbee.private_methods(false).include?(method.to_s)
     end
 
   end
Index: lib/mocha/class_method.rb
===================================================================
--- lib/mocha/class_method.rb (revision 334)
+++ lib/mocha/class_method.rb (working copy)
@@ -74,11 +74,12 @@
     end
     
     def method_exists?(method)
-      existing_methods = []
-      existing_methods += stubbee.public_methods(true) - stubbee.superclass.public_methods(true)
-      existing_methods += stubbee.protected_methods(true) - stubbee.superclass.protected_methods(true)
-      existing_methods += stubbee.private_methods(true) - stubbee.superclass.private_methods(true)
-      existing_methods.any? { |m| m.to_s == method.to_s }
+      stubbee.public_method_defined?(method.to_sym) ||
+      !stubbee.superclass.public_method_defined?(method.to_sym) ||
+      stubbee.protected_method_defined?(method.to_sym) ||
+      !stubbee.superclass.protected_method_defined?(method.to_sym) ||
+      stubbee.private_method_defined?(method.to_s)  ||
+      !stubbee.superclass.private_method_defined?(method.to_s) 
     end
 
   end
Index: lib/mocha/any_instance_method.rb
===================================================================
--- lib/mocha/any_instance_method.rb  (revision 334)
+++ lib/mocha/any_instance_method.rb  (working copy)
@@ -43,11 +43,9 @@
     end
 
     def method_exists?(method)
-      existing_methods = []
-      existing_methods += stubbee.public_instance_methods(false)
-      existing_methods += stubbee.protected_instance_methods(false)
-      existing_methods += stubbee.private_instance_methods(false)
-      existing_methods.any? { |m| m.to_s == method.to_s }
+      stubbee.public_method_defined?(method.to_sym) ||
+      stubbee.protected_method_defined?(method.to_sym) ||
+      stubbee.private_method_defined?(method.to_s) 
     end
     
   end
Index: lib/mocha/instance_method.rb
===================================================================
--- lib/mocha/instance_method.rb  (revision 334)
+++ lib/mocha/instance_method.rb  (working copy)
@@ -5,11 +5,9 @@
   class InstanceMethod < ClassMethod
 
     def method_exists?(method)
-      existing_methods = []
-      existing_methods += stubbee.public_methods(false)
-      existing_methods += stubbee.protected_methods(false)
-      existing_methods += stubbee.private_methods(false)
-      existing_methods.any? { |m| m.to_s == method.to_s }
+      stubbee.public_methods(false).include?(method.to_s) ||
+      stubbee.protected_methods(false).include?(method.to_s) ||
+      stubbee.private_methods(false).include?(method.to_s)
     end
 
   end