instance method
extract!
Ruby on Rails 2.12.0
Since v2.4.1 Last seen in v2.14.1Signature
extract!(object, *attributes)
Extracts the mentioned attributes or hash elements from the passed object and turns them into attributes of the JSON.
Example:
@person = Struct.new(:name, :age).new('David', 32)
or you can utilize a Hash
@person = { name: 'David', age: 32 }
json.extract! @person, :name, :age
{ "name": David", "age": 32 }, { "name": Jamie", "age": 31 }
You can also use the call syntax instead of an explicit extract! call:
json.(@person, :name, :age)
Parameters
-
objectreq -
attributesrest
Source
# File lib/jbuilder.rb, line 247
def extract!(object, *attributes)
if ::Hash === object
_extract_hash_values(object, attributes)
else
_extract_method_values(object, attributes)
end
end
Defined in lib/jbuilder.rb line 247
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Jbuilder