jbuilder
https://github.com/rails/jbuilder
Ruby
Jbuilder: generate JSON objects with a Builder-style DSL
Jbuilder#extract!
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)Edit
git clone [email protected]:rails/jbuilder.git
cd jbuilder
open lib/jbuilder.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Jbuilder-extract--for-pr
# Commit to gitgit add lib/jbuilder.rbgit commit -m "better docs for Jbuilder#extract!"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Jbuilder-extract--for-pr
hub pull-request
# Celebrate!