Method: ActionController::Base#instantiate_from_hash

Defined in:
app/controllers/rails_ext.rb

#instantiate_from_hash(clazz, attr_hash) ⇒ Object



16
17
18
19
20
21
22
23
# File 'app/controllers/rails_ext.rb', line 16

def instantiate_from_hash(clazz, attr_hash)
  object = clazz.new
  attr_hash.each do |attr_name, attr_value|
    setter = attr_name[1..-1] + "="
    object.__send__(setter.to_sym, attr_value) if object.respond_to?(setter.to_sym)
  end
  object
end