Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/hashd/hash.rb
Instance Attribute Summary collapse
-
#use_dot_syntax ⇒ Object
Returns the value of attribute use_dot_syntax.
Instance Method Summary collapse
-
#method_missing(name, *args, &block) ⇒ Object
Using method missing.
- #to_dot ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Using method missing.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hashd/hash.rb', line 10 def method_missing(name, *args, &block) return super(name, *args, &block) unless use_dot_syntax # Check for value first or assign if name[-1] == '=' return self[name[0..-2].to_sym] = args[0] elsif (val = self[name] || self[name.to_s]) return val end # Pass to methods if value not found return super(name, *args, &block) if self.respond_to?(name) end |
Instance Attribute Details
#use_dot_syntax ⇒ Object
Returns the value of attribute use_dot_syntax.
3 4 5 |
# File 'lib/hashd/hash.rb', line 3 def use_dot_syntax @use_dot_syntax end |
Instance Method Details
#to_dot ⇒ Object
5 6 7 |
# File 'lib/hashd/hash.rb', line 5 def to_dot dotify(self); self end |