Ruby中未输入GetoptLong::REQUIRED_参数时报告错误
我有一个非常简单的Ruby代码:Ruby中未输入GetoptLong::REQUIRED_参数时报告错误,ruby,Ruby,我有一个非常简单的Ruby代码: #!/res/software/pkg/ruby-2.0.0/bin/ruby -w require( 'getoptlong' ) opts = GetoptLong.new( [ '--netlist_file', GetoptLong::REQUIRED_ARGUMENT ] ) puts 'error in getting netlist' << opts.error_message.to_s() 当没有输入任何GetoptLong::RE
#!/res/software/pkg/ruby-2.0.0/bin/ruby -w
require( 'getoptlong' )
opts = GetoptLong.new( [ '--netlist_file', GetoptLong::REQUIRED_ARGUMENT ] )
puts 'error in getting netlist' << opts.error_message.to_s()
当没有输入任何GetoptLong::REQUIRED_参数时,我如何能出错?
有通用的方法吗?
谢谢
cs059:Florida_domains$ ~/test.rb
error in getting netlist
require( 'getoptlong' )
begin
opts = GetoptLong.new( [ '--netlist_file', GetoptLong::REQUIRED_ARGUMENT ] )
opts.each do |option, arg|
case option
when "--netlist_file"
#assign the argument to my_var or do whatever you need to do with it
my_var = arg
end
rescue => e
puts "Error in arguments"
puts e.to_s
end