lib/xkeys.rb in xkeys-0.0.1 vs lib/xkeys.rb in xkeys-0.0.2

- old
+ new

@@ -1,15 +1,29 @@ # XKeys - Extended keys to facilitate fetching and storing in nested # hash and array structures with Perl-ish auto-vivification. # # Synopsis: # root = {}.extend XKeys::Hash +# root[:my, :list, nil] = 'value 1' +# root[:my, :list, nil] = 'value 2' +# root[:sparse, 10] = 'value 3' +# # => { :my => { :list => [ 'value 1', 'value 2' ] }, +# # :sparse => { 10 => 'value 3' } } +# root[:missing] # => nil +# root[:missing, :else => false] # => false +# root[:missing, {}] # => raises KeyError +# # root = [].extend XKeys::Auto +# root[1, nil] = 'value 1' +# root[1, 3] = 'value 2' +# # => [ nil, [ 'value 1', nil, nil, 'value 2' ] ] +# root[0, 1] # => [ nil ] (slice of length 1 at 0) +# root[nil, 1, 0] # => 'value 1' # -# Author:: Brian Katzung <briank@kappacs.com>, Kappa Computer Solutions, LLC -# Copyright:: 2013 Brian Katzung and Kappa Computer Solutions, LLC -# License:: MIT License +# @author Brian Katzung <briank@kappacs.com>, Kappa Computer Solutions, LLC +# @copyright 2013 Brian Katzung and Kappa Computer Solutions, LLC +# @license MIT License module XKeys; end # Extended fetch and get ([]) module XKeys::Get @@ -112,10 +126,10 @@ module XKeys::Set_Auto include XKeys::Set_ # Auto-vivify nested hash and/or array trees using extended hash # key/array index assignment syntax. Nil keys and integer keys - # created nested arrays as needed. Other keys create nested hashes + # create nested arrays as needed. Other keys create nested hashes # as needed. # # root[key1, ..., keyN] = value def []= (*args) super *args unless