M
Matt Rose
This has been bugging me for weeks now, intermittently.
By all accounts I've read, this getoptlong code should work
require 'getoptlong'
opts = GetoptLong.new(
["--devel","-d",GetoptLong::NO_ARGUMENT],
["--getpass","-g",GetoptLong::NO_ARGUMENT],
["--debug","-D",GetoptLong::NO_ARGUMENT],
["--verbose","-V",GetoptLong::NO_ARGUMENT]
)
server = 'http://192.168.10.16/'
verbose = false
opts.each { |o,a| p o }
opts.each { |o,a|
case o
when '--devel'
server = 'http://192.168.20.56/'
when '--getpass'
puts "this option does nothing"
when '--debug': $DEBUG = true
when '--verbose': verbose = true
end
}
p server
p $DEBUG
p verbose
This is the output I expect when I run it:
"--devel"
"--debug"
"--verbose"
"http://192.168.20.56/"
true
true
This is the output I get:
"--devel"
"--debug"
"--verbose"
"http://192.168.10.16/"
false
false
What am I missing?
By all accounts I've read, this getoptlong code should work
require 'getoptlong'
opts = GetoptLong.new(
["--devel","-d",GetoptLong::NO_ARGUMENT],
["--getpass","-g",GetoptLong::NO_ARGUMENT],
["--debug","-D",GetoptLong::NO_ARGUMENT],
["--verbose","-V",GetoptLong::NO_ARGUMENT]
)
server = 'http://192.168.10.16/'
verbose = false
opts.each { |o,a| p o }
opts.each { |o,a|
case o
when '--devel'
server = 'http://192.168.20.56/'
when '--getpass'
puts "this option does nothing"
when '--debug': $DEBUG = true
when '--verbose': verbose = true
end
}
p server
p $DEBUG
p verbose
This is the output I expect when I run it:
"--devel"
"--debug"
"--verbose"
"http://192.168.20.56/"
true
true
This is the output I get:
"--devel"
"--debug"
"--verbose"
"http://192.168.10.16/"
false
false
What am I missing?