Module: UtilityBelt::PrintMethods

Defined in:
lib/utility_belt/print_methods.rb

Constant Summary collapse

INSPECTORS =
[
:public_methods,
:public_instance_methods,
:protected_methods,
:protected_instance_methods,
:private_methods,
:private_instance_methods
]

Instance Method Summary collapse

Instance Method Details



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
# File 'lib/utility_belt/print_methods.rb', line 45

def print_methods(inspector = nil)
  buffer = []
  kself = self.class == Class ? self : self.class
  clist = kself.included_modules
  clist -= Object.included_modules unless kself == Object
  clist = clist.map { |m| m.name }.reject { |m| m =~ /UtilityBelt/ || m =~ /Wirble/ }.sort.map { |m| m.constantize }
  clist.unshift(kself.superclass) if kself.superclass && kself.superclass != Object
  clist.unshift(kself)

  inspector_methods = INSPECTORS.include?(inspector) ? [inspector] : INSPECTORS
  clist.each do |klass|
    inspector_methods.each do |insmethod|
      mlist = klass.send(insmethod).sort
      mlist -= klass.superclass.send(insmethod) if klass.respond_to?(:superclass) && clist.include?(klass.superclass)
      mlist -= Object.send(insmethod) unless klass == Object
      mlist -= ['append_features'] # dunno where this method comes from
      unless mlist.empty?
        return mlist if inspector_methods.size == 1
        buffer << "=== #{klass.name} === #{mlist.size} #{insmethod.to_s.split('_').join(' ')}"
        buffer << mlist.join(", ")
        buffer << ""
      end
    end
  end
  puts buffer.join("\n")
  nil
end