in your first test case, it will not return an error because -1
is also considered as an Integer
#irb output
2.0.0-p247 :003 > a = -1
=> -1
2.0.0-p247 :004 > a.is_a?(Integer)
=> true
and in your second case, when you pass a string, it will error even before going inside your condition as you are trying to compare string with an integer
#irb outout
2.0.0-p247 :007 > "hello" < 0
ArgumentError: comparison of String with 0 failed
from (irb):7:in `<'
from (irb):7
and off topic, you could write
if n.is_a?(Integer) == false
raise 'strings are not acceptable'
end
as (more ruby way :))
raise 'strings are not acceptable' unless n.is_a?(Integer)