Class: GmHashWrapper::StrictHashWrapper
- Inherits:
-
HashWrapper
- Object
- HashWrapper
- GmHashWrapper::StrictHashWrapper
- Defined in:
- lib/gm_hash_wrapper/strict_hash_wrapper.rb
Instance Attribute Summary
Attributes inherited from HashWrapper
Instance Method Summary collapse
Methods inherited from HashWrapper
#as_json, #each, #initialize, #nil?, #present?, #respond_to_missing?, #set_data, #to_h
Constructor Details
This class inherits a constructor from GmHashWrapper::HashWrapper
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gm_hash_wrapper/strict_hash_wrapper.rb', line 7 def method_missing meth, *args, &block if @body.has_key?(meth) if @body[meth].kind_of?(Hash) return StrictHashWrapper.new(@body[meth]) elsif @body[meth].kind_of?(Array) return @body[meth].map do |x| if x.kind_of?(Hash) StrictHashWrapper.new(x) else x end end else return @body[meth] end else raise("undefined method \'#{meth}\' for #{body}") end end |
Instance Method Details
#key?(key) ⇒ Boolean
3 4 5 |
# File 'lib/gm_hash_wrapper/strict_hash_wrapper.rb', line 3 def key?(key) @body.has_key?(key) end |