Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created November 6, 2011 00:30
Show Gist options
  • Save leejarvis/88f890540376794559ab to your computer and use it in GitHub Desktop.
Save leejarvis/88f890540376794559ab to your computer and use it in GitHub Desktop.
diff --git a/lib/slop.rb b/lib/slop.rb
index 6993cb1..812ded4 100644
--- a/lib/slop.rb
+++ b/lib/slop.rb
@@ -265,6 +265,41 @@ class Slop
end
end
+ module Optionize
+ class << self
+ attr_accessor :options
+ attr_accessor :slops
+ end
+
+ self.options = Hash.new([])
+ self.slops = {}
+
+ def self.included(into)
+ into.extend ClassMethods
+ into.send(:include, InstanceMethods)
+ end
+
+ module ClassMethods
+ def option(*args)
+ Optionize.options[self] << args
+ end
+ end
+
+ module InstanceMethods
+ def parse_options(args)
+ slop = Slop.new
+ Optionize.options[self.class].each { |opts| slop.on(*opts) }
+ slop.parse(args)
+ Optionize.slops[self] = slop
+ slop
+ end
+
+ def options
+ Optionize.slops[self]
+ end
+ end
+ end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment