Shopify / measured-rails

Rails adapter for the measured gem. Encapsulate measurements and their units in Ruby and Rails.
MIT License
92 stars 13 forks source link

Do not read an instance variable if it is not defined. #50

Closed kmcphillips closed 6 years ago

kmcphillips commented 6 years ago

In some cases, where we are overriding the names of the properties used, we will read an ivar that does not yet exist.

It will return nil but ruby will spit out a warning.

Here we guard against that and just have it return nil without reading if it is not defined. Removes these warnings:

/measured-rails/lib/measured/rails/active_record.rb:37: warning: instance variable @measured_length not initialized
/measured-rails/lib/measured/rails/active_record.rb:37: warning: instance variable @measured_total_weight not initialized
/measured-rails/lib/measured/rails/active_record.rb:37: warning: instance variable @measured_width not initialized
/measured-rails/lib/measured/rails/active_record.rb:37: warning: instance variable @measured_width not initialized
/measured-rails/lib/measured/rails/active_record.rb:37: warning: instance variable @measured_width not initialized
/measured-rails/lib/measured/rails/active_record.rb:37: warning: instance variable @measured_width not initialized