Raise ArgumentError from method : Fixnum class « Number « Ruby






Raise ArgumentError from method


def Fixnum.random(min, max)
  raise ArgumentError, "min > max" if min > max
  return min + rand(max-min+1)
end
Fixnum.random(10, 20)                             # => 13
Fixnum.random(-5, 0)                              # => -5
Fixnum.random(10, 10)                             # => 10
Fixnum.random(20, 10)
# ArgumentError: min > max

 








Related examples in the same category

1.Fixnum literal value
2.Normal-looking math equations when you use operator methods, such as +
3.Extend the Fixnum class with some helper methods to make manipulating dates easier
4.Output the modules where Fixnum lives
5.find out the ancestors of Fixnum