First parse!
with optparse, then scan the ARGV and raise if ARGV is empty. Like so:
op.parse!
filename = ARGV.pop
raise "Need to specify a file to process" unless filename
The mandatory filename will not be processed by the OptionParser
and will be left for you in ARGV – if it’s not there, just raise manually.