class Jbuilder
def extract!(object, *attributes)
You can also use the call syntax instead of an explicit extract! call:
{ "name": David", "age": 32 }, { "name": Jamie", "age": 31 }
json.extract! @person, :name, :age
@person = { name: 'David', age: 32 }
or you can utilize a Hash
@person = Struct.new(:name, :age).new('David', 32)
Example:
Extracts the mentioned attributes or hash elements from the passed object and turns them into attributes of the JSON.
def extract!(object, *attributes) if ::Hash === object _extract_hash_values(object, attributes) else _extract_method_values(object, attributes) end end