Forum: Ruby on Rails Setting Up Setters

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8bc74268b4cfc767f683b70bf4245a37?d=identicon&s=25 rapdup (Guest)
on 2009-05-07 22:56
(Received via mailing list)
If I have a setter method that needs to manipulate the incoming value
before setting itself, how can I do this without it be self
referencing? In the example below, I've defined "start_date=", so how
do I now save a value to start_date?

thx

Ex:
class Event
   def start_date=(new_start_date)
       self.start_date = new_start_date unless new_start_date >=
start_date
   end
end
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-07 23:04
(Received via mailing list)
On 7 May 2009, at 13:55, rapdup <nathan@rapheld.org> wrote:

>
> If I have a setter method that needs to manipulate the incoming value
> before setting itself, how can I do this without it be self
> referencing? In the example below, I've defined "start_date=", so how
> do I now save a value to start_date?
>

Look for write_attribute

Fred
This topic is locked and can not be replied to.