module VisibilityChecker
Constants
- VisibilityChange
Structure holding data on method visibility changes
Public Class Methods
visibility_changes(klass, stop_at: Object, skip_owners: [Kernel])
click to toggle source
Return an array of VisibilityChanges for any changes in method visibility in any of the the ancestors of klass
before stop_at
, unless the owner of the method is in skip_owners
. This will be an empty array if there are no visibility changes.
# File lib/visibility_checker.rb 8 def self.visibility_changes(klass, stop_at: Object, skip_owners: [Kernel]) 9 meths = {} 10 changes = [] 11 12 klass.ancestors.each do |mod| 13 break if mod == stop_at 14 15 [:public, :private, :protected].each do |vis_type| 16 mod.send("#{vis_type}_instance_methods").each do |meth| 17 prev_vis_type, prev_mod = meths[meth] 18 unless prev_vis_type.nil? || prev_vis_type == vis_type 19 owner = mod.instance_method(meth).owner 20 unless skip_owners.include?(owner) 21 changes << VisibilityChange.new(meth, mod.instance_method(meth).owner, vis_type, prev_mod, prev_vis_type) 22 end 23 end 24 meths[meth] = [vis_type, mod] 25 end 26 end 27 end 28 29 changes 30 end
Public Instance Methods
visibility_changes()
click to toggle source
Detect visibility changes in the receiver's ancestors. This should only be used if you are extending a class or module with VisibilityChecker
or including it in Class or Module.
# File lib/visibility_checker.rb 35 def visibility_changes 36 VisibilityChecker.visibility_changes(self) 37 end