Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/hash.rb
Class Attribute Summary collapse
-
.hash_dot_use_default ⇒ Object
Returns the value of attribute hash_dot_use_default.
-
.use_dot_syntax ⇒ Object
Returns the value of attribute use_dot_syntax.
Instance Attribute Summary collapse
-
#hash_dot_use_default ⇒ Object
Returns the value of attribute hash_dot_use_default.
-
#use_dot_syntax ⇒ Object
Returns the value of attribute use_dot_syntax.
Instance Method Summary collapse
- #method_missing(method, *args) ⇒ Object
- #respond_to?(method, include_all = false) ⇒ Boolean
- #to_dot(use_default: false) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hash.rb', line 18 def method_missing(method, *args) return super(method, *args) unless to_dot? method, chain = method.to_s.split(".", 2).map(&:to_sym) return send(method).send(chain, *args) if chain prop = create_prop(method) if setter?(method) self[prop] = args.first elsif key?(prop) || use_default? self[prop] else super(method, args) end end |
Class Attribute Details
.hash_dot_use_default ⇒ Object
Returns the value of attribute hash_dot_use_default.
6 7 8 |
# File 'lib/hash.rb', line 6 def hash_dot_use_default @hash_dot_use_default end |
.use_dot_syntax ⇒ Object
Returns the value of attribute use_dot_syntax.
5 6 7 |
# File 'lib/hash.rb', line 5 def use_dot_syntax @use_dot_syntax end |
Instance Attribute Details
#hash_dot_use_default ⇒ Object
Returns the value of attribute hash_dot_use_default.
10 11 12 |
# File 'lib/hash.rb', line 10 def hash_dot_use_default @hash_dot_use_default end |
#use_dot_syntax ⇒ Object
Returns the value of attribute use_dot_syntax.
9 10 11 |
# File 'lib/hash.rb', line 9 def use_dot_syntax @use_dot_syntax end |
Instance Method Details
#respond_to?(method, include_all = false) ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/hash.rb', line 36 def respond_to?(method, include_all = false) return super(method, include_all) unless to_dot? prop = create_prop(method) return true if key?(prop) super(method, include_all) end |
#to_dot(use_default: false) ⇒ Object
12 13 14 15 16 |
# File 'lib/hash.rb', line 12 def to_dot(use_default: false) dotify_hash(self, use_default: use_default) self end |