Permalink
Browse files

Simplify number parsing logic in numericality validation

  • Loading branch information...
carlosantoniodasilva committed Nov 15, 2013
1 parent f70e30e commit d2992818e02bd380f6a68385b4e97a301ec2f8aa
Showing with 3 additions and 10 deletions.
  1. +3 −10 activemodel/lib/active_model/validations/numericality.rb
@@ -56,16 +56,9 @@ def validate_each(record, attr_name, value)
protected
def parse_raw_value_as_a_number(raw_value)
- case raw_value
- when /\A0[xX]/
- nil
- else
- begin
- Kernel.Float(raw_value)
- rescue ArgumentError, TypeError
- nil
- end
- end
+ Kernel.Float(raw_value) if raw_value !~ /\A0[xX]/
+ rescue ArgumentError, TypeError
+ nil
end
def parse_raw_value_as_an_integer(raw_value)

0 comments on commit d299281

Please sign in to comment.