instance method extract!

Ruby on Rails 2.12.0

Since v2.4.1 Last seen in v2.14.1

Available in: v2.4.1 v2.5.0 v2.6.4 v2.7.0 v2.8.0 v2.9.1 v2.10.2 v2.11.5 v2.12.0 v2.13.0 v2.14.1

Signature

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

object req
attributes rest
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

Type at least 2 characters to search.

↑↓ navigate · open · esc close