Method: Serial::Serializer#initialize

Defined in:
lib/serial/serializer.rb

#initialize {|builder, value| ... } ⇒ Serializer

Create a new Serializer, using the block as instructions.

Examples:

# app/serializers/person_serializer.rb
PersonSerializer = Serial::Serializer.new do |h, person|
  h.attribute(:name, person.name)
end

Yields:

  • (builder, value)

Yield Parameters:


15
16
17
18
19
20
21
22
# File 'lib/serial/serializer.rb', line 15

def initialize(&block)
  unless block_given?
    raise ArgumentError, "instructions (block) is required"
  end

  @block = block
  @to_proc = method(:to_proc_implementation).to_proc
end