Sha256: e7e3fe61c1f0681aa83561311359ab9e79a8cd569e40947f93f4fd1a5598cd0a

Contents?: true

Size: 1.81 KB

Versions: 10

Compression:

Stored size: 1.81 KB

Contents

class Module

  # Detect conflicts.
  #
  #   module A
  #     def c; end
  #   end
  #
  #   module B
  #     def c; end
  #   end
  #
  #   A.conflict?(B)  #=> ["c"]
  #
  #
  #   TODO: All instance methods, or just public?
  #
  # CREDIT: Thomas Sawyer, Robert Dober

  def conflict?(other)
    common_ancestor = (ancestors & other.ancestors).first
    c = []
    c += (public_instance_methods(true) & other.public_instance_methods(true))
    c += (private_instance_methods(true) & other.private_instance_methods(true))
    c += (protected_instance_methods(true) & other.protected_instance_methods(true))
    c -= common_ancestor.public_instance_methods(true)
    c -= common_ancestor.private_instance_methods(true)
    c -= common_ancestor.protected_instance_methods(true)
    c.empty? ? false : c
  end

  #def conflict?(other)
  #  c = instance_methods & other.instance_methods
  #  c.empty ? false : c
  #end

  # Like #conflict?, but checks only public methods.
  def public_conflict?(other)
    common_ancestor = (ancestors & other.ancestors).first
    c = public_instance_methods(true) & other.public_instance_methods(true)
    c -= common_ancestor.public_instance_methods(true)
    c.empty? ? false : c
  end

  # Like #conflict?, but checks only private methods.
  def private_conflict?(other)
    common_ancestor = (ancestors & other.ancestors).first
    c = private_instance_methods(true) & other.private_instance_methods(true)
    c -= common_ancestor.private_instance_methods(true)
    c.empty? ? false : c
  end

  # Like #conflict?, but checks only protected methods.
  def protected_conflict?(other)
    common_ancestor = (ancestors & other.ancestors).first
    c = protected_instance_methods(true) & other.protected_instance_methods(true)
    c -= common_ancestor.protected_instance_methods(true)
    c.empty? ? false : c
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/module/conflict.rb
facets-2.8.3 lib/core/facets/module/conflict.rb
facets-2.8.2 lib/core/facets/module/conflict.rb
facets-2.8.1 lib/core/facets/module/conflict.rb
facets-2.8.0 lib/core/facets/module/conflict.rb
facets-2.7.0 lib/core/facets/module/conflict.rb
facets-2.6.0 lib/core/facets/module/conflict.rb
facets-2.5.1 lib/core/facets/module/conflict.rb
facets-2.5.0 lib/core/facets/module/conflict.rb
facets-2.5.2 lib/core/facets/module/conflict.rb