Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2016 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6a1e4a2b85028de36b2a03dadf8b1793 to your computer and use it in GitHub Desktop.
Save anonymous/6a1e4a2b85028de36b2a03dadf8b1793 to your computer and use it in GitHub Desktop.
if :symbols are immutable how can you use :symbols with default values and then change?
@options = {:user => "john",
:password => nil,
:host => nil,
:warn => 100,
:crit => 500}
opt = OptionParser.new
opt.on("--user USER", "Connect as user") do |f|
@options[:user] = f
end
opt.on("--password PASSWORD", "Connection password") do |f|
@options[:password] = f
end
opt.on("--host HOST", "Host to connect to") do |f|
if @options[:host]
@options[:host] << f
else
@options[:host] = [f]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment