diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ayk/options.rb | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/lib/ayk/options.rb b/lib/ayk/options.rb index 13b3e40..5650609 100644 --- a/lib/ayk/options.rb +++ b/lib/ayk/options.rb @@ -48,10 +48,8 @@ module AYK def option doc, key, value, other = {}, &block ks = key.to_sym raise OptionsError.new("Overriding existing option #{key}") if pedantic? and @hash.has_key? ks - trigger = block || other[:trigger] - convert = {:doc => doc.to_s, :value => value} - convert[:trigger] = trigger if trigger - @hash[ks] = other.merge(convert) + other[:trigger] = block if block + @hash[ks] = other.merge( :doc=>doc.to_s, :value=>value ) end alias o option # @@ -73,14 +71,14 @@ module AYK # this block should behave like Proc.new { |new_value,prev_value| ... } def trigger key, &block ks = key.to_sym - raise OptionError.new("Setting trigger for unknown option : #{key}") if pedantic? and not @hash.has_key? ks + raise OptionsError.new("Setting trigger for unknown option : #{key}") if pedantic? and not @hash.has_key? ks @hash[ks][:trigger] = block end # # To avoid lookup on the parent, we can set a default to the internal Hash. # Parameters as in {Options#o}, but without the +key+. def default doc, value, other={} - @hash.default = other.merge(:doc => doc, :value => value) + @hash.default = other.merge(:doc=>doc, :value=>value) end # # Try to retrieve the corresponding Hash for the passed keys, will try to @@ -97,7 +95,7 @@ module AYK nil end elsif sub_options = get(key) - sub_options.get(*keys) + sub_options[*keys] end end private :get @@ -132,19 +130,6 @@ module AYK self[meth] end end -# # -# # @param [Array] keys -# # @param [Object] value -# def set_value(keys, value) -# got = get(*keys) -# return got[:value] = value if got -# raise(IndexError, "There is no option available for %p" % [keys]) -# end -# def merge!(hash) -# hash.each_pair do |key, value| -# set_value(key.to_s.split('.'), value) -# end -# end # def to_hash; @hash end def each █ @hash.each(&block) end |