lib/args_parser/parser.rb in args_parser-0.0.6 vs lib/args_parser/parser.rb in args_parser-0.0.7
- old
+ new
@@ -8,35 +8,32 @@
parser.parse argv
parser
end
class Parser
- attr_reader :first
+ attr_reader :argv, :params, :aliases
- private
- def params
- @params ||=
- Hash.new{|h,k|
+ public
+ def first
+ argv.first
+ end
+
+ def initialize(config, &block)
+ unless block_given?
+ raise ArgumentError, 'initialize block was not given'
+ end
+ @config = config
+ @argv = []
+ @params = Hash.new{|h,k|
h[k] = {
:default => nil,
:description => nil,
:value => nil,
:alias => nil,
:index => -1
}
}
- end
-
- def aliases
- @aliases ||= Hash.new
- end
-
- public
- def initialize(config, &block)
- @config = config
- unless block_given?
- raise ArgumentError, 'initialize block was not given'
- end
+ @aliases = {}
@filter = Filter.new
@validator = Validator.new
instance_eval(&block)
filter do |v|
(v.kind_of? String and v =~ /^\d+$/) ? v.to_i : v