class EasyHash::HashToObject
Attributes
hash[R]
Public Class Methods
new(hash)
click to toggle source
# File lib/easy_hash.rb, line 9 def initialize(hash) @hash = hash end
Public Instance Methods
method_missing(method, *)
click to toggle source
Calls superclass method
# File lib/easy_hash.rb, line 13 def method_missing(method, *) hash_object = hash[method.to_sym] return super if hash_object.nil? return self.class.new(hash_object) if hash_object.is_a?(Hash) return convert_to_array_of_objects(hash_object) if hash_object.is_a?(Array) hash_object end
respond_to_missing?(method, *)
click to toggle source
Calls superclass method
# File lib/easy_hash.rb, line 22 def respond_to_missing?(method, *) return super if hash.nil? || hash[method.to_sym].nil? hash[method.to_sym] end
to_h()
click to toggle source
# File lib/easy_hash.rb, line 28 def to_h hash end
Private Instance Methods
convert_to_array_of_objects(hash_object)
click to toggle source
# File lib/easy_hash.rb, line 34 def convert_to_array_of_objects(hash_object) hash_object.map { |ha| self.class.new(ha) } end