You can define the “number” ‘infinity’ (or ‘-infinity’) in Ruby like this:
1.0/0 => Infinity -1.0/0 => -Infinity
Infinity and -Infinity behave just like you expect them to: they are always bigger - or always smaller, respectively - than any number you compare it to.
The Xing Devblog had a great post recently about using Ruby’s infinity in Rails, with some thoughts on when you might want to use it (or not).
P.S.: the Float class in Ruby 1.9.2 provides an Infinity constant you can use:
Float::INFINITY => Infinity
This tip was submitted by makoto.
You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.