Module: SY::ExpressibleInUnits::DetectRedefine
- Defined in:
- lib/sy/expressible_in_units.rb
Overview
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.
Instance Method Summary collapse
Instance Method Details
#method_added(ß) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 |