Ruby won’t let you divide an integer by zero—you’ll get an exception. However, thanks to the IEEE 754 standard for floating point numbers, when you try to divide a float by zero you get a rather special value back:
puts 1.0/0
#-> Infinity
It’s not a constant though, it’s just how that floating point result is represented as a string. However, you can easily assign that value to a constant:
Infinity = 1.0/0
Once you have that, you can use it for all kinds of nifty things; throw it in ranges, use it in comparisons, whatever suits your fancy:
# a rather useless range
everything = -Infinity..Infinity
puts everything.include?(5) #-> true
# use it for representing an unbounded value
storage_limits => { :demo => 0,
:standard => 250.megabytes,
:expert => 1.gigabyte,
:unlimited => Infinity }
if bytes_used < storage_limits[account_level]
# add another file or something
else
# display "out of space" message
end