Module: ActiveAttr::BlockInitialization

Extended by:
ActiveSupport::Concern
Includes:
ChainableInitialization
Included in:
Model
Defined in:
lib/active_attr/block_initialization.rb

Overview

BlockInitialization allows you to build an instance in a block

Including the BlockInitialization module into your class will yield the model instance to a block passed to when creating a new instance.

Examples:

Usage

class Person
  include ActiveAttr::BlockInitialization
end

Since:

  • 0.3.0

Instance Method Summary collapse

Instance Method Details

#initialize {|_self| ... } ⇒ Object

Initialize a model and build via a block

Examples:

person = Person.new do |p|
  p.first_name = "Chris"
  p.last_name = "Griego"
end

person.first_name #=> "Chris"
person.last_name #=> "Griego"

Yields:

  • (_self)

Yield Parameters:

Since:

  • 0.3.0



32
33
34
35
# File 'lib/active_attr/block_initialization.rb', line 32

def initialize(*)
  super
  yield self if block_given?
end