Voldemort Voldemort - 1 year ago 77
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
print "Error: Expected integer value"

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download