-
-
Save leejarvis/88f890540376794559ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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