From: Ritesh Agrawal Date: 2011-03-03T03:53:59+09:00 Subject: array of valid arguments in optparse Hi, I am trying to use optparse to parse an argument into an array and check for possible values. For instance consider an argument like this --operations count, count+, count- I want to parse above argument into @options[:operations] = ["count", "count+", "count-"]. But at the same time I have limited vocabulary for possible operations and I want to check for that so that if some gives any other operation argument, it throws an error message @OPERATIONS=["count", "count+", "count-"] @optparse = OptionParser.new do |opts| opts.banner = "Usage: ruby #{__FILE__} --operations=METHOD1,METHOD2,METHOD3.." opts.on('-o OPERATIONS', '--operations a,b,c', @OPERATIONS, Array, "Possible operations are #{@OPERATIONS.join(', ')}" ) do |hypo| @options[:operations]=[] unless @options[:operations] @options[:operations] << hypo.to_s.strip.downcase() @options[:operations] = @options[:operations].uniq end end @optparse.parse! -- Posted via http://www.ruby-forum.com/.