class Jbuilder

def array!(collection = [], *attributes, &block)

[1,2,3]

json.array! [1, 2, 3]

If you omit the block then you can set the top level array directly:

{ "people": [ { "name": David", "age": 32 }, { "name": Jamie", "age": 31 } ] }

end
json.age calculate_age(person.birthday)
json.name person.name
json.people(@people) do |person|

It's generally only needed to use this method for top-level arrays. If you have named arrays, you can do:

json.(@people) { |person| ... }

You can use the call syntax instead of an explicit extract! call:

[ { "name": David", "age": 32 }, { "name": Jamie", "age": 31 } ]

end
json.age calculate_age(person.birthday)
json.name person.name
json.array!(@people) do |person|

Example:

an element of the resulting array.
Turns the current element into an array and iterates over the passed collection, adding each iteration as
def array!(collection = [], *attributes, &block)
  array = if collection.nil?
    []
  elsif ::Kernel.block_given?
    _map_collection(collection, &block)
  elsif attributes.any?
    _map_collection(collection) { |element| extract! element, *attributes }
  else
    _format_keys(collection.to_a)
  end
  @attributes = _merge_values(@attributes, array)
end