lib/configurable/indifferent_access.rb in configurable-0.1.0 vs lib/configurable/indifferent_access.rb in configurable-0.3.0

- old
+ new

@@ -1,22 +1,35 @@ module Configurable + + # Implements AGET and ASET methods that symbolize string keys, in effect + # producing indifferent access. IndifferentAccess is intended to extend + # a Hash. + # + # Note that the indifference produced by this module is very thin indeed. + # Strings may still be used as keys through store/fetch, and + # existing string keys are not changed in any way. Nonetheless, + # these methods are sufficient for Configurable and DelegateHash. module IndifferentAccess - + + # Symbolizes string keys and calls super. def [](key) super(convert(key)) end - + + # Symbolizes string keys and calls super. def []=(key, value) super(convert(key), value) end - - def key?(key) - super(convert(key)) + + # Ensures duplicates use indifferent access. + def dup + super().extend IndifferentAccess end - + private - - def convert(key) + + # a helper to convert strings to symbols + def convert(key) # :nodoc: key.kind_of?(String) ? key.to_sym : key end end end \ No newline at end of file