On Sep 17, 2014, at 9:09 AM, Matteo Panara <matteo.pan...@gmail.com> wrote:

> Why not?
> 
> module ActiveModel
>   module Validations
>     class NumericalityValidator < EachValidator
>       CHECKS = { greater_than: :>, greater_than_or_equal_to: :>=,
>                 equal_to: :==, less_than: :<, less_than_or_equal_to: :<=,
>                 multiple_of: :multiple_of?, odd: :odd?, even: :even?,
>                 odd: :odd?, even: :even?, other_than: :!= }.freeze
> 

multiple_of isn’t a supported option for NumericalityValidator because the 
method only exists for integers. Here’s some previous discussion of this 
situation:

https://github.com/rails/rails/pull/7216 (on why multiple_of isn’t defined for 
all of Numeric)

https://github.com/rails/rails/pull/7213 (on adding this exact feature)

TL;DR the core of the problem is that % is a tricky operator for floating-point 
numbers. 1.0 % 0.1, for instance, is usually NOT 0.0 like you’d expect…

—Matt Jones


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to