Re: Overwriting default accessors

Hi Marnen

On Oct 12, 3:04 pm, Marnen Laibow-Koser
[email protected] wrote:

hoping that this accessors would be able to set or change the value of
:status. But the behaviours doesn’t seems to be like that.

It can be, but you’ll have to do it slightly differently. I’ll help
you, but you’re going to have to explain exactly what you want to have
happen.

The point is I want to set the value of the status before it is saved
to the database.

So what is
this accessors used for? Is it only for the view level?

No. It’s just that your syntax wasn’t quite correct.

Many thanks.


Certified Scrum Master
http://blog.scrum8.com | http://jobs.scrum8.com |
http://twitter.com/scrum8

Joshua P. wrote:

Hi Marnen

On Oct 12, 3:04 pm, Marnen Laibow-Koser
[email protected] wrote:

hoping that this accessors would be able to set or change the value of
:status. But the behaviours doesn’t seems to be like that.

It can be, but you’ll have to do it slightly differently. I’ll help
you, but you’re going to have to explain exactly what you want to have
happen.

The point is I want to set the value of the status before it is saved
to the database.

Then you want something like

def status=(value)
new_value = do_something_to(value)
self[:status] = new_value # assuming this class is derived from AR
end

The reason your attempt to do status = value didn’t work is that it was
just calling the same method.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]