I'm trying to override a initialize in a ActiveRecord model, I just saw one thing that I could not understand what was happening there. I wrote this initialize method:
def initialize params={}
super params
@data = Date.strptime(params[:data], '%d/%m/%Y') if not params[:data].nil?
self.number = generate_contract_number(params[:unit]) if not params[:unit].nil?
self
end
Given the generate_contract_number works and Date.strptime works as well. My question is: Why when I do self.number= the number is set and when I do @number= the number is not set. But when I do just the same with @contract_date= it works, and the self.contract_date= is set automatically?
Thanks