From: 7stud -- Date: 2009-04-30T15:31:23+09:00 Subject: Re: Can this code be more succinct botp wrote: > On 4/30/09, Mark Thomas wrote: >> but I'm not sure whether the number of args check can be handled >> inside the case. I tried a 'when ARGV.size > 1' but you can't put a >> full expression in a when statement. >> > > there's another form for case. > try this (untested), > > arg = ARGV[0] > case > when ARGV.size > 1 > abort "too many args ;-)" > when /^os$/ =~ arg > sym = arg.downcase > else > abort "ERROR: invalid arg #{arg}" > end ...but then instead of having to look up the format of a case statement, you could just write: val = "red" if val == "blue" puts "blue" elsif val == "red" abort "code red" else puts "not recognized" end puts "program terminating normally" -- Posted via http://www.ruby-forum.com/.