…if you can avoid it, like
$<. Instead, use their english aliases like
One caveat: with the exception of
$LOAD_PATH (an alias for
$0), you need to
require "english" before you can use the english aliases. I'd love to see
english included into Ruby itself.
And while we're at it:
STDINare constants, and while you can actually reassign constants in Ruby, you shouldn't. If you rely on the global variables instead, it's much easier to redirect
$stdoutto something else, for example.
$stderr.puts. That's what
warnis there for, after all. And it allows you to surpress warnings if you really need to (by setting the warn level to 0 via
abortif you need to immediately terminate for some reason.
Floatif you need to make sure the string you're converting actually contains an integer or a float. Observe:
>> "not a float".to_f
>> Float("not a float")
ArgumentError: invalid value for Float(): "not a float"
>> "not an integer".to_i
>> Integer("not an integer")
ArgumentError: invalid value for Integer(): "not an integer"
Refer to Christian Neukirchen's Ruby Style Guide for more general info on how you can (and probably should) format your Ruby code.
(Hat-tip to @manveru, who pointed out the incorrect usage of