Voldemort Voldemort - 1 month ago 7
Ruby Question

Can I tell a Ruby method to expect a specific parameter type?

def doSomething(value)
if (value.is_a?(Integer))
print value * 2
else
print "Error: Expected integer value"
exit
end
end


Can I tell a Ruby method that a certain parameter should be an Integer, otherwise crash? Like Java.

Answer

No, you can't. You can only do what you're already doing: check the type yourself.