Forum: Ruby on Rails Dirty.rb - confused

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.
Timbo (Guest)
on 2009-01-31 13:50
(Received via mailing list)
Hi Guys,

I am working with Active Record 2.1.x and there is a file called
dirty.rb. Now I might be missing something but within the function
write_attribute_with_dirty there is a call to
write_attribute_without_dirty. Where is the definition for this
function? What happens after this call?

Thanks,

Tim.
javier ramirez (Guest)
on 2009-01-31 15:24
(Received via mailing list)
> I am working with Active Record 2.1.x and there is a file called
> dirty.rb. Now I might be missing something but within the function
> write_attribute_with_dirty there is a call to
> write_attribute_without_dirty. Where is the definition for this
> function? What happens after this call?
>

that's a common idiom in Rails. They are using an alias to the original
"write_attribute" so they can intercept the calls to write_attribute, do
whatever is needed for the "dirty" functionality and then call to the
original "write_attribute" (without_dirty).

you can do this by using several alias statements or you can use the
alias_method_chain method provided by the Rails API.

by using the strategy of naming/aliasing the methods using the
with/without suffix, you can be (almost) sure that even if you are
aliasing a method that was already aliased, everything will be peachy.

AFAIK in Rails 3 this could change, since the Merb guys are not happy
(and with a reason) about so many levels of indirection and the
complexity introduced in the code. But as of now, it's a common pattern
all throughout Rails code and plugins.


regards,

--
javier ramírez

..i do ruby on rails development in madrid, spain, at
http://www.aspgems.com
..you can find out more about me on http://formatinternet.wordpress.com
and http://workingwithrails.com/person/5987-javier-ramirez
This topic is locked and can not be replied to.