I'm using case to do stuff based on some options that get passed on the
command line. I've got the following bit of code that is doing this for me:
require 'getoptlong'
opts = GetoptLong.new(
['-t', GetoptLong::REQUIRED_ARGUMENT ],
['-n', GetoptLong::REQUIRED_ARGUMENT ],
['-s', GetoptLong::REQUIRED_ARGUMENT ]
)
opts.each do |opt, arg|
# puts "Option: #{opt}, arg #{arg.inspect}"
case opt
when "-t" then title = #{arg.inspect}
when "-n" then nation = #{arg.inspect}
when "-s" then submitter = #{arg.inspect}
else puts "You shouldn't be here with #{opt} and #{arg.inspect}
end
end
This is taken with very little alteration from TPP (page 83: Case
Expressions). But when I run this code, I get the following error:
eris> ./new-deck.rb -t foo -n bar -s baz
./new-deck.rb:27: parse error
when "-n" then nation = #{arg.inspect}
^
./new-deck.rb:33: unterminated string meets end of file
./new-deck.rb:33: parse error
Can someone tell me where I've lost my way here?
--
Dylan Northrup <*> docx / io.com <*> http://www.io.com/~docx/
"Easy to bitch, easy to whine, easy to moan, easy to cry, easy to feel like
there ain't nothing in your life. Harder to work, harder to strive, hard to
be glad to be alive, but it's really worth it if you give it a try."
-- Cowboy Mouth, 'Easy'