On 8 January 2011 11:54, Mauro <[email protected]> wrote:
> [...]
> in the instance method
>
> def expiry_date
>  self.issue_date + 90.days
> end
>
> I can do
>
> def expiry_date
>  issue_date + 90.days
> end
>
> without the word self.
> Is it the same thing?

Including the self keyword just ensures that it uses issue_date from
the current object.  It jensures that the correct variable is used in
case there was another variable of the same name in scope.  Some like
to do this as a matter of principle.  I would always use self when
*assigning* to an instance variable as otherwise a slight misspelling
will silently write to a local variable rather than the instance
variable.

>
> Specifically I've done in my model:
>
> def default_date
>    Date.new(1970, 01, 01)
> end
>
> def durc_expiry_date
>  unless durc_issue_date.eql?(default_date)
>    durc_issue_date + 90.days
>  else
>    default_date
>  end
> end

I would generally use null in the database as the default date rather
than a specific value, but that is possibly a matter of taste.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to