Module: Cowtech::Extensions::Hash
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cowtech-extensions/hash.rb
Overview
Extensions for Hash objects.
Instance Method Summary collapse
-
#method_missing(method, *args, &block) ⇒ Object
This is called when the user access a member using dotted notation.
-
#respond_to?(method) ⇒ Boolean
This is called when the user access a member using dotted notation.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
This is called when the user access a member using dotted notation.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cowtech-extensions/hash.rb', line 19 def method_missing(method, *args, &block) rv = nil if self.has_key?(method.to_sym) then rv = self[method.to_sym] elsif self.has_key?(method.to_s) then rv = self[method.to_s] else rv = ::Hash.method_missing(method, *args, &block) end rv end |
Instance Method Details
#respond_to?(method) ⇒ Boolean
This is called when the user access a member using dotted notation.
37 38 39 |
# File 'lib/cowtech-extensions/hash.rb', line 37 def respond_to?(method) (self.has_key?(method.to_sym) || self.has_key?(method.to_s)) ? true : ::Hash.respond_to?(method) end |