matthew-method_lister 0.3.1 → 0.3.2

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.
@@ -40,11 +40,11 @@ module MethodLister
40
40
  end
41
41
 
42
42
  def inspect
43
- repr = "object=#{object.inspect}"
43
+ repr = "object=#{object.inspect}\n"
44
44
  VISIBILITIES.each do |visibility|
45
- repr += " #{visibility}=#{methods(visibility).sort.inspect}"
45
+ repr += "#{visibility}=#{methods(visibility).sort.inspect}\n"
46
46
  end
47
- "<#{repr}>"
47
+ repr
48
48
  end
49
49
  end
50
50
  end
@@ -73,27 +73,33 @@ module MethodLister
73
73
  end
74
74
  end
75
75
 
76
+ # This method is awfully complicated and does not give accurate answers
77
+ # because the reflection methods for eigenclasses do not work correctly.
78
+ # The singleton_methods(false) call will return all public and protected
79
+ # singleton methods, but not the private ones. And the
80
+ # *_instance_methods(false) calls will include the methods defined on the
81
+ # class in addition to singleton methods. c.f the following test scenarios:
82
+ # mixed_visibility_methods.rb and cloned_eigenclass.rb
76
83
  def record_methods_for_eigenclass(object)
77
84
  @seen[object] = true
78
85
  return unless eigenclass = get_eigenclass(object)
79
86
 
80
- # This complication arises because the methods used to do reflection on
81
- # eigenclasses will return methods from the object's class. For public
82
- # and protected methods we can determine where the method came from, but
83
- # for private methods we have to do a heuristic guess. c.f. scenario
84
- # "mixed_visibility_methods.rb"
85
- singleton_methods = object.singleton_methods(false)
86
- public_methods = eigenclass.public_instance_methods(false)
87
- protected_methods = eigenclass.protected_instance_methods(false)
88
- private_methods = eigenclass.private_instance_methods(false)
89
- ancestor_privates = eigenclass.ancestors.map do |ancestor|
90
- ancestor.private_instance_methods(false)
91
- end.flatten.uniq
87
+ our_public_methods = eigenclass.public_instance_methods(false)
88
+ our_protected_methods = eigenclass.protected_instance_methods(false)
89
+ our_private_methods = eigenclass.private_instance_methods(false)
90
+
91
+ ancestor_methods = Hash.new
92
+ [:public, :protected, :private].each do |method_type|
93
+ ancestor_methods[method_type] = eigenclass.ancestors.map do |ancestor|
94
+ ancestor.send("#{method_type}_instance_methods", false)
95
+ end.flatten.uniq
96
+ end
92
97
 
93
98
  record_result(object,
94
- :public => singleton_methods & public_methods,
95
- :protected => singleton_methods & protected_methods,
96
- :private => private_methods - ancestor_privates)
99
+ :public => our_public_methods - ancestor_methods[:public],
100
+ :protected => our_protected_methods - ancestor_methods[:protected],
101
+ :private => our_private_methods - ancestor_methods[:private]
102
+ )
97
103
 
98
104
  scan_modules(:eigenclass, object)
99
105
  end
@@ -17,10 +17,11 @@ module MethodListerMatchers
17
17
  str, n = "", 0
18
18
  @expected.zip(@target).each do |expected, got|
19
19
  if expected != got
20
- str += <<-MESSAGE
21
- Expected[#{n}]: #{expected.inspect}
22
- Got[#{n}]: #{got.inspect}
23
-
20
+ str += <<-MESSAGE
21
+ Expected[#{n}]:
22
+ #{expected.inspect}
23
+ Got[#{n}]:
24
+ #{got.inspect}
24
25
  MESSAGE
25
26
  end
26
27
  n += 1
@@ -22,10 +22,13 @@ module FindScenarioNameSpace
22
22
  end
23
23
 
24
24
  @expected = [
25
- result(@object, :public => ["eigen_public", "common_public" ],
26
- :protected => ["eigen_protected", "common_protected"],
27
- :private => ["eigen_private" ]),
28
- # :private => ["eigen_private", "common_private" ]),
25
+ # The commented out lines is the desired result, but can't make it work.
26
+ # result(@object, :public => ["eigen_public", "common_public" ],
27
+ # :protected => ["eigen_protected", "common_protected"],
28
+ # :private => ["eigen_private", "common_private" ]),
29
+ result(@object, :public => ["eigen_public"],
30
+ :protected => ["eigen_protected"],
31
+ :private => ["eigen_private"]),
29
32
  result(MyModule, :public => ["module_public", "common_public" ],
30
33
  :protected => ["module_protected", "common_protected"],
31
34
  :private => ["module_private", "common_private" ]),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matthew-method_lister
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew O'Connor