@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?
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?