lib/unitwise/ext/numeric.rb in unitwise-1.0.1 vs lib/unitwise/ext/numeric.rb in unitwise-1.0.2
- old
+ new
@@ -18,16 +18,18 @@
# 100.to_foot # => #<Unitwise::Measurement 100 foot>
# @api semipublic
def method_missing(meth, *args, &block)
if args.empty? && !block_given?
unit = (match = /\Ato_(\w+)\Z/.match(meth.to_s)) ? match[1] : meth
- begin
- res = convert_to(unit)
- Numeric.define_unit_conversion_methods_for(unit)
- res
+ converted = begin
+ convert_to(unit)
rescue Unitwise::ExpressionError
- super(meth, *args, &block)
+ nil
end
+ end
+ if converted
+ Numeric.define_unit_conversion_methods_for(unit)
+ converted
else
super(meth, *args, &block)
end
end