# = populate.rb

require 'facets/core/kernel/populate'

# A class mixin for objects which initialize using a hash or block
# to simply populate attr_writers/accessors.
# 
#   class MyClass
#     include Populate
#     attr :a
#   end
#
#   m = MyClass.new(:a=>1)
#   m.a  #=> 1
#
#   m = MyClass.new{ |s| s.a = 1 }
#   m.a  #=> 1
#   

module Populate

  # Populating initializer.

  def initialize( data=nil, &block ) #:yield:
    before_initialize_populate
    populate(data, &block)
    after_initialize_populate
  end

  # When using, a class should generally leave the initializer
  # alone and just fillout these two callbacks as needed.

  def before_initialize_populate  ; end
  def after_initialize_populate ; end

end

