def hash_to_model(klass_name, hash)
      model_klass =
        if self.class.const_defined?("#{self.class}::#{klass_name}")
          self.class.const_get(klass_name)
        else
          self.class.const_set(klass_name, Class.new(HashModel))
        end
      model_klass.new(hash)
    end
def hash_to_model(klass_name, hash)
      model_klass =
        if self.class.const_defined?("#{self.class}::#{klass_name}")
          self.class.const_get(klass_name)
        else
          self.class.const_set(klass_name, Class.new(HashModel))
        end
      model_klass.new(hash)
    end
Convert a hash to an instance of nested model class

 This is the default implementation; the resulting object is based on HashModel
 To be overridden by subclasses