module Dottie::Methods
Public Instance Methods
[](key)
click to toggle source
[]=(key, value)
click to toggle source
Writes to the Hash
or Array
with special handling for Dottie-style keys, adding missing Hash
nodes or Array
elements where necessary.
Calls superclass method
# File lib/dottie/methods.rb, line 19 def []=(key, value) if Dottie.dottie_key?(key) Dottie.set(wrapped_object_or_self, key, value) else super end end
delete(key)
click to toggle source
Deletes the value at the specified key and returns it.
Calls superclass method
# File lib/dottie/methods.rb, line 62 def delete(key) if Dottie.dottie_key?(key) Dottie.delete(wrapped_object_or_self, key) else super end end
dottie_flatten()
click to toggle source
# File lib/dottie/methods.rb, line 73 def dottie_flatten Dottie.flatten(wrapped_object_or_self) end
dottie_keys(intermediate = false)
click to toggle source
# File lib/dottie/methods.rb, line 80 def dottie_keys(intermediate = false) Dottie.keys(wrapped_object_or_self, intermediate: intermediate) end
fetch(key, default = :_fetch_default_, &block)
click to toggle source
Fetches a value from the Hash
with special handling for Dottie-style keys. Handles the optional default value and block the same as Hash#fetch.
# File lib/dottie/methods.rb, line 43 def fetch(key, default = :_fetch_default_, &block) if Dottie.dottie_key?(key) if default != :_fetch_default_ Dottie.fetch(wrapped_object_or_self, key, default, &block) else Dottie.fetch(wrapped_object_or_self, key, &block) end else if default != :_fetch_default_ wrapped_object_or_self.fetch(key, default, &block) else wrapped_object_or_self.fetch(key, &block) end end end
has_key?(key)
click to toggle source
Checks whether the Hash
has the specified key with special handling for Dottie-style keys.
Calls superclass method
# File lib/dottie/methods.rb, line 31 def has_key?(key) if Dottie.dottie_key?(key) Dottie.has_key?(wrapped_object_or_self, key) else super end end
Private Instance Methods
wrapped_object_or_self()
click to toggle source
Gets the Hash
or Array
, whether it is a wrapped object (a Dottie::Freckle
) or this object (self).
# File lib/dottie/methods.rb, line 90 def wrapped_object_or_self if is_a?(Hash) || is_a?(Array) self elsif respond_to?(:wrapped_object) wrapped_object || self else self end end