From: "Jesús Gabriel y Galán" Date: 2012-07-27T02:15:36+09:00 Subject: Re: optparse problem grabbing a value On Thu, Jul 26, 2012 at 6:58 PM, James Harrison wrote: > #!/usr/bin/env ruby > require "ostruct" > require "optparse" > > options = OpenStruct.new > > options.date = false > > option_parser = OptionParser.new do |opts| > opts.on("-d", "--date", String, "Optional: Specify date in format > 00-00-00") do |date| > options.date = date > end > end > > puts "<#{options.date}>" This works: #!/usr/bin/env ruby require "ostruct" require "optparse" options = OpenStruct.new options.date = false option_parser = OptionParser.new do |opts| opts.on("-d", "--date DATE", String, "Optional: Specify date in format 00-00-00") do |date| options.date = date end end option_parser.parse! puts "<#{options.date}>" I had to add the DATE parameter in the long format specification and also call parse!: ./test.rb -d "12-10-12" <12-10-12> Jesus.