Ruby Language Default values


Example

With OptionsParser, it's really easy to set up default values. Just pre-populate the hash you store the options in:

options = {
  :directory => ENV['HOME']
}

When you define the parser, it will overwrite the default if a user provide a value:

OptionParser.new do |opts|
  opts.on("-d", "--directory HOME", "Directory to use") do |d|
    options[:directory] = d
  end
end