lib/xkeys.rb in xkeys-2.0.1 vs lib/xkeys.rb in xkeys-2.1.0

- old
+ new

@@ -25,12 +25,15 @@ # # As of version 2.0.0, underlying types must implement #[], #[]=, and # #fetch to be supported (see the Array or Hash class documentation). # They must also implement #push if you want to use push mode (index ":[]"). # -# Version 2.0.1 2014-04-16 +# As of version 2.1.0, #[] is used if #fetch is not supported. Missing-key +# detection (still) depends on KeyError or IndexError being raised. # +# Version 2.1.0 2014-05-06 +# # @author Brian Katzung <briank@kappacs.com>, Kappa Computer Solutions, LLC # @copyright 2013-2014 Brian Katzung and Kappa Computer Solutions, LLC # @license MIT License module XKeys; end @@ -62,10 +65,10 @@ if args[-1].is_a?(Hash) then options, last = args[-1], -2 else options, last = {}, -1 end args[0..last].inject(self) do |node, key| - begin node.fetch key + begin node.respond_to?(:fetch) ? node.fetch(key) : node[key] rescue KeyError, IndexError if options[:raise] && options[:raise] != true raise *options[:raise] elsif options[:raise] || !options.has_key?(:else) raise