Module: Dottie::Methods
- Included in:
- Freckle
- Defined in:
- lib/dottie/methods.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Reads from the Hash or Array with special handling for Dottie-style keys.
-
#[]=(key, value) ⇒ Object
Writes to the Hash or Array with special handling for Dottie-style keys, adding missing Hash nodes or Array elements where necessary.
-
#delete(key) ⇒ Object
Deletes the value at the specified key and returns it.
- #dottie_flatten ⇒ Object
- #dottie_keys(intermediate = false) ⇒ Object
-
#fetch(key, default = :_fetch_default_, &block) ⇒ Object
Fetches a value from the Hash with special handling for Dottie-style keys.
-
#has_key?(key) ⇒ Boolean
Checks whether the Hash has the specified key with special handling for Dottie-style keys.
Instance Method Details
#[](key) ⇒ Object
Reads from the Hash or Array with special handling for Dottie-style keys.
9 10 11 12 13 14 15 |
# File 'lib/dottie/methods.rb', line 9 def [](key) if Dottie.dottie_key?(key) Dottie.get(wrapped_object_or_self, key) else super end end |
#[]=(key, value) ⇒ Object
Writes to the Hash or Array with special handling for Dottie-style keys, adding missing Hash nodes or Array elements where necessary.
21 22 23 24 25 26 27 |
# File 'lib/dottie/methods.rb', line 21 def []=(key, value) if Dottie.dottie_key?(key) Dottie.set(wrapped_object_or_self, key, value) else super end end |
#delete(key) ⇒ Object
Deletes the value at the specified key and returns it.
64 65 66 67 68 69 70 |
# File 'lib/dottie/methods.rb', line 64 def delete(key) if Dottie.dottie_key?(key) Dottie.delete(wrapped_object_or_self, key) else super end end |
#dottie_flatten ⇒ Object
75 76 77 |
# File 'lib/dottie/methods.rb', line 75 def dottie_flatten Dottie.flatten(wrapped_object_or_self) end |
#dottie_keys(intermediate = false) ⇒ Object
82 83 84 |
# File 'lib/dottie/methods.rb', line 82 def dottie_keys(intermediate = false) Dottie.keys(wrapped_object_or_self, intermediate: intermediate) end |
#fetch(key, default = :_fetch_default_, &block) ⇒ Object
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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dottie/methods.rb', line 45 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) ⇒ Boolean
Checks whether the Hash has the specified key with special handling for Dottie-style keys.
33 34 35 36 37 38 39 |
# File 'lib/dottie/methods.rb', line 33 def has_key?(key) if Dottie.dottie_key?(key) Dottie.has_key?(wrapped_object_or_self, key) else super end end |