Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Interface
- class << self
- def cli(*opts,&block)
- @@parser ||= OptionParser.new
- @@parser.on_tail *opts, &block
- end
- def parse_args(args=ARGV)
- @options = {}
- #access options here works, obvious ;)
- @@parser.on("-d",String,"Some default flag") do |value|
- @options[:default_flag]=value
- end
- @@parser.parse!(args)
- end
- end
- end
- class ThingThatUsesInterface
- #this always gets nil for @options, if i do w/o the @ it bombs
- Interface.cli("-m",String,"My Cool flag") do |value|
- @option[:my_cool_flag] = value
- end
- end
Add Comment
Please, Sign In to add comment