SwiftkickWeb / FOODweek

Code for the meal planning app, Food Week
http://www.foodweek.me
0 stars 0 forks source link

Refactor ingredient existence check in that one model where I'm rescuing the exception #151

Open johnhutch opened 6 years ago

johnhutch commented 6 years ago

See comment here: https://github.com/olbrich/ruby-units/issues/156#issuecomment-352649106

@johnhutch I think you can use Unit.defined?("unitname") for this purpose. Edit: Unit.defined? does not recognize prefixes so it won't work for those cases e.g. Unit.defined?('cm') is false but Unit.new('cm') will work.

Could this lead to cleaner, more efficient code than the exception rescue?