I am wondering how do I pass a false value to my ruby script.
If I invoke:
ruby myscript.rb false
and then in my script if I say:
my_class.new(*ARGV)
or my_class.new(ARGV[0])
basically a string with value "false" gets passed. Clearly if I say
if(ARGV[0]){ do something} .. this gets executed even if value passed is false.
Can I change my function signature to auto-covert paramter to boolean ..so that I dont have to do
if(ARGV[0]=='true')
You need to evaluate the command-line argument. Anything passed on the command line is a string, that's all the command line knows about.
For example, you could monkey-patch String (untested):
class String
def to_b
self =~ /^(true|t|yes|y|1)$/i
end
end
Or write a utility, or use the command-line option parser (long-term best bet), or...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With