# Dirty.rb - confused

**URL:** <https://www.ruby-forum.com/t/dirty-rb-confused/159088>\
**Category:** Rails\
**Created:** [January 31, 2009, 12:50pm UTC](https://www.ruby-forum.com/t/dirty-rb-confused/159088 "2009-01-31T12:50:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Timbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ad7895/32.png) [@Timbo](https://www.ruby-forum.com/u/Timbo)\
**Post date:** [January 31, 2009, 12:50pm UTC](https://www.ruby-forum.com/t/dirty-rb-confused/159088/1 "2009-01-31T12:50:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Timbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ad7895/32.png) [@Timbo](https://www.ruby-forum.com/u/Timbo)\
**Post date:** [January 31, 2009, 2:24pm UTC](https://www.ruby-forum.com/t/dirty-rb-confused/159088/2 "2009-01-31T14:24:22Z")

</div>

> 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](http://www.aspgems.com)  
…you can find out more about me on [http://formatinternet.wordpress.com](http://formatinternet.wordpress.com)  
and [http://workingwithrails.com/person/5987-javier-ramirez](http://workingwithrails.com/person/5987-javier-ramirez)
