module SY::ExpressibleInUnits::DetectRedefine

This is a mixin for the target class of this mixin, that causes it to warn upon detecting newly defined methods shadowing the SY unit methods.

Public Instance Methods

method_added(ß) click to toggle source
# File lib/sy/expressible_in_units.rb, line 14
def method_added ß
  # warn "#{self}: method added: :#{ß}"
  uu = ::SY::ExpressibleInUnits.known_units
  nn = uu.map &:name
  aa = uu.map &:abbreviation
   = Hash[ nn.zip( uu ) ].merge Hash[ aa.zip( uu ) ]
  w = ::SY::ExpressibleInUnits::REDEFINE_WARNING % [ ß, self ]
  if nn.include? ß then
    if instance_methods.include? ß then
      im = instance_method ß
      warn w unless ::SY::ExpressibleInUnits.method_family.include? im if
        [ß].warns? unless instance_variable_get( :@no_collision ) == ß
      instance_variable_set( :@no_collision, nil )
    else
      warn w if [ß].warns?
    end
  end
  if aa.include? ß then
    if instance_methods.include? ß then
      im = instance_method ß
      warn w unless ::SY::ExpressibleInUnits.method_family.include? im if
        [ß].warns? unless instance_variable_get( :@no_collision ) == ß
      instance_variable_set( :@no_collision, nil )
    else
      warn w if [ß].warns?
    end
  end
end