Class: Finix::IndifferentHash
- Inherits:
-
Hash
- Object
- Hash
- Finix::IndifferentHash
- Defined in:
- lib/finix/indifferent_hash.rb
Instance Method Summary collapse
- #count(*args) ⇒ Object
-
#initialize(*args) ⇒ IndifferentHash
constructor
A new instance of IndifferentHash.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ IndifferentHash
Returns a new instance of IndifferentHash.
4 5 6 7 |
# File 'lib/finix/indifferent_hash.rb', line 4 def initialize(*args) original_hash = args.slice!(0) || {} self.merge!(original_hash) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/finix/indifferent_hash.rb', line 9 def method_missing(method, *args, &block) if self.has_key? "#{method}" value = self["#{method}"] return value.call(*args) if value.respond_to? :call return value end end |
Instance Method Details
#count(*args) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/finix/indifferent_hash.rb', line 17 def count(*args) if self.has_key? 'count' raise Exception.new 'Unsupported block_given exception' if block_given? return self.send :method_missing, :count, *args end super(*args) end |