DrBoolean / Set-Attribute-Order

Declare an order for setters

This URL has Read+Write access

name age message
file README Loading commit data...
file set_attribute_order.rb
file untitled 2513.rb
file untitled 2513.txt
README
Sets attributes by the order you pass in then continues as usual.

Usage:

class Boy < ActiveRecord::Base
  set_attribute_order :mom, :dad, :sister
  
  def  dad=(value)
    puts "SET DAD"
    @dad = value
  end
  
  def  dog=(value)
    puts "SET DOG"
    @dog = value
  end
  
  def  mom=(value)
    puts "SET MOM"
    @mom = value
  end
  
  def  sister=(value)
    puts "SET SISTER"
    self.build_sister(:mom => @mom, :dad => @dad)
  end
  
end

Boy.create(:dad => "Bill", :sister => "Kate", :mom => "Kim")
=> "SET MOM"
=> "SET DAD"
=> "SET SISTER"


Boy.create(:dad => "Bill", :mom => "Kim")
=> "SET MOM"
=> "SET DAD"


Boy.create(:dog => "Ralph", :mom => "Kim", :dad => "Bill")
=> "SET MOM"
=> "SET DAD"
=> "SET DOG"