Sha256: a88e9fac1dc4bd0b6f79b641224f6e2df16a42551f7eca0c39669e374c8edb94

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

class Module

  # Detect method name clash between modules and/or classes, regardless of
  # method visibility:
  #
  #   module MethodClashExample
  #
  #     module A
  #       def c; end
  #     end
  #
  #     module B
  #       private
  #       def c; end
  #     end
  #
  #     A.method_clash(B)  #=> [:c]
  #
  #   end
  #
  # CREDIT: Thomas Sawyer, Robert Dober
  #
  #--
  # TODO: Should method_clash just be public methods? ...
  #++
  def method_clash(other)
    common_ancestor = (ancestors & other.ancestors).first

    s = []
    s += public_instance_methods(true)
    s += private_instance_methods(true)
    s += protected_instance_methods(true)

    o = []
    o += other.public_instance_methods(true)
    o += other.private_instance_methods(true)
    o += other.protected_instance_methods(true)

    c = s & o

    if common_ancestor
      c -= common_ancestor.public_instance_methods(true)
      c -= common_ancestor.private_instance_methods(true)
      c -= common_ancestor.protected_instance_methods(true)
    end

    return c
  end

  # Uses #method_clash to return +true+ or +false+ if there
  # are method name clashes.
  def method_clash?(other) 
    c = method_clash(other) 
    !c.empty?
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
facets-2.9.1 lib/core/facets/module/method_clash.rb
facets-2.9.0 lib/core/facets/module/method_clash.rb
facets-2.9.0.pre.2 lib/core/facets/module/method_clash.rb
facets-2.9.0.pre.1 lib/core/facets/module/method_clash.rb