I make use of Integer( param )
in Ruby and NUM2INT( param )
in native extensions as a way of accepting any param that could be cast to an Integer in my public interfaces.
Recently I came across a difference in behaviour between Ruby 1.8 and 1.9 where 1.9 raises an error, but 1.8 makes an unwanted coercion from Symbol
to Fixnum
(or to an equivalent int
in C):
In 1.9.3, behaviour I want:
1.9.3-p327 :001 > Integer( :foo )
TypeError: can't convert Symbol into Integer
In 1.8.7, behaviour I don't want:
1.8.7 :001 > Integer( :foo )
=> 15081
This came out as I asserted TypeError in a test when sending in a Symbol param instead of Integer, and I got some Travis fails as a result. For now, I've stopped using Symbol
s as examples of bad parameters in my test. But could/should I do more for 1.8.7 compatibility?