On Jul 20, 11:20 pm, Learn By Doing <[email protected]> wrote:
> Hi David,
>
> The reason I need to redefine the assignment and make it private is
> that because whenever x is assigned a new value, some other processes
> must take place:
Why not override x= then rather than inventing a new set_x method ?
>
> def set_x(val)
> self.x = val
> # some other processes take place here
> end
>
> private
>
> def x=(val)
> super
> end
>
> I don't understand when you say that there is no built-in method for
> "x=". How else can one assign value to an attribute?
The setter methods get generated on the fly for you (the default ones
just end up calling write_attribute) as David explained - you can't
mark them as private or override and use super to call the original
implementation because the method doesn't exist yet.
Fred
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---