diff options
Diffstat (limited to 'activemodel/lib/active_model/validations/numericality.rb')
-rw-r--r-- | activemodel/lib/active_model/validations/numericality.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb index 9c1e8b4ba7..ad7012df48 100644 --- a/activemodel/lib/active_model/validations/numericality.rb +++ b/activemodel/lib/active_model/validations/numericality.rb @@ -39,6 +39,10 @@ module ActiveModel return end + unless raw_value.is_a?(Numeric) + value = parse_raw_value_as_a_number(raw_value) + end + options.slice(*CHECKS.keys).each do |option, option_value| case option when :odd, :even @@ -63,12 +67,15 @@ module ActiveModel protected def is_number?(raw_value) - parsed_value = Kernel.Float(raw_value) if raw_value !~ /\A0[xX]/ - !parsed_value.nil? + !parse_raw_value_as_a_number(raw_value).nil? rescue ArgumentError, TypeError false end + def parse_raw_value_as_a_number(raw_value) + Kernel.Float(raw_value) if raw_value !~ /\A0[xX]/ + end + def is_integer?(raw_value) /\A[+-]?\d+\z/ === raw_value.to_s end |