Method: Optimist::Parser#initialize
- Defined in:
- lib/optimist.rb
#initialize(*a, &b) ⇒ Parser
Initializes the parser, and instance-evaluates any block given.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/optimist.rb', line 136 def initialize(*a, &b) @version = nil @leftovers = [] @specs = {} @long = {} @short = {} @order = [] @constraints = [] @stop_words = [] @stop_on_unknown = false @educate_on_error = false @synopsis = nil @usage = nil ## allow passing settings through Parser.new as an optional hash. ## but keep compatibility with non-hashy args, though. begin settings_hash = Hash[*a] @settings = DEFAULT_SETTINGS.merge(settings_hash) a=[] ## clear out args if using as settings-hash rescue ArgumentError @settings = DEFAULT_SETTINGS end self.instance_exec(*a, &b) if block_given? end |