Ruby >
Table of Contents [hide]
Force a pause ∞
This will not work as expected when a script is run with arguments.
puts "<PAUSED>" pause=gets
Any arguments are collected into an array called ARGV
, and if there is anything in that array then gets
will think of these arguments as files for it to read from. This is clearly not what we want.
The solution is simple. Clear the ARGV
array so that gets
always reads from the commandline.
puts "<PAUSED>" ARGV.clear pause=gets
Also, if you don't want to create the variable "pause", you could have ARGV
and gets
work together directly, like this:
puts "<PAUSED>" ARGV.clear ARGV << gets
Issues with nil
∞
Having stupid problems with nil
not acting like "0"? Well, you could redefine what it is:
class NilClass def [] nil #or whatever you want returned end end
Confirmed the date of creation.