the price is supposed to be a string in number format but can include
other non-digital characters like ‘a’, since :only_integer is set to
false by default, right?
In rails implementation, it use Kernel.Float to complete the work. But
seems Kernel.Float(ruby 1.8.6) always throw an exception when the
number string contains non-digital characters, such as “123.00a”. So
in fact there is no diffierences whether the switch :only_integer is
turned on or off.
I found in JRuby, the Kernel.Float will accept string that looks like
“123.00a” but will finally return a zero.
only_integer means it will only allow integers. Otherwise, decimal
places are allowed. You will need to write a custom method to
validate the “numericality” of strings containing alpha characters.
number string contains non-digital characters, such as “123.00a”. So
in fact there is no diffierences whether the switch :only_integer is
turned on or off.
I found in JRuby, the Kernel.Float will accept string that looks like
“123.00a” but will finally return a zero.
Do I misunderstand of the :only_integer switch?
Integer would mean 100 vs 100.0
I’m new to Ruby, so maybe there’s something unique, but why would you
think 123.00a is a float?
[123, 123.00, -123.00].each do |n|
puts n.is_a?(Float)
end
#false #true #true
Trying to put in a number like 123.00a in that array makes it fail.
–
def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end