Method: Serial::HashBuilder#map

Defined in:
lib/serial/hash_builder.rb

#map(key, list) {|builder, value| ... } ⇒ Object

Declare a collection attribute from a list of values.

Examples:

h.map(:people, project.people) do |h, person|
  h.attribute(:name, person.name)
end # => { "people" => [{ "name" => … }] }

Parameters:

  • key (#to_s)
  • list (#each)

Yields:

  • (builder, value)

    yields each value from list to build an array of hashes

Yield Parameters:

See Also:


97
98
99
100
# File 'lib/serial/hash_builder.rb', line 97

def map(key, list, &block)
  check_duplicate_key!(key)
  map!(key, list, &block)
end