Guest User

Untitled

a guest
May 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. class Interface
  2. class << self
  3. def cli(*opts,&block)
  4. @@parser ||= OptionParser.new
  5. @@parser.on_tail *opts, &block
  6. end
  7.  
  8. def parse_args(args=ARGV)
  9. @options = {}
  10.  
  11. #access options here works, obvious ;)
  12. @@parser.on("-d",String,"Some default flag") do |value|
  13. @options[:default_flag]=value
  14. end
  15.  
  16. @@parser.parse!(args)
  17. end
  18. end
  19.  
  20. end
  21.  
  22.  
  23. class ThingThatUsesInterface
  24. #this always gets nil for @options, if i do w/o the @ it bombs
  25. Interface.cli("-m",String,"My Cool flag") do |value|
  26. @option[:my_cool_flag] = value
  27. end
  28. end
Add Comment
Please, Sign In to add comment