# Decorator pattern in Ruby... what do you think about the implementation?

**URL:** <https://www.ruby-forum.com/t/decorator-pattern-in-ruby-what-do-you-think-about-the-implementation/188278>\
**Category:** Rails\
**Created:** [May 9, 2010, 8:30am UTC](https://www.ruby-forum.com/t/decorator-pattern-in-ruby-what-do-you-think-about-the-implementation/188278 "2010-05-09T08:30:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samiron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@samiron](https://www.ruby-forum.com/u/samiron)\
**Post date:** [May 9, 2010, 8:30am UTC](https://www.ruby-forum.com/t/decorator-pattern-in-ruby-what-do-you-think-about-the-implementation/188278/1 "2010-05-09T08:30:26Z")

</div>

Hello all  
I was wondering about how you guys are implementing the decorator  
patterns in Ruby? Here is a thought to share with.  
[Tagged - The social network for meeting new people](http://digs.by/9Rezfs).  
Could you please share your thoughts about this implementation?

Have a great time 🙂  
Take care.

---

<div class="post-metadata">

**Author:** ![samiron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@samiron](https://www.ruby-forum.com/u/samiron)\
**Post date:** [May 9, 2010, 8:40pm UTC](https://www.ruby-forum.com/t/decorator-pattern-in-ruby-what-do-you-think-about-the-implementation/188278/2 "2010-05-09T20:40:55Z")

</div>

On 09 May 2010, at 08:28, Samiron wrote:

> I was wondering about how you guys are implementing the decorator  
> patterns in Ruby? Here is a thought to share with. [Tagged - The social network for meeting new people](http://digs.by/9Rezfs)  
> .  
> Could you please share your thoughts about this implementation?

You could easily do that in a few lines:  
[http://lukeredpath.co.uk/blog/decorator-pattern-with-ruby-in-8-lines.html](http://lukeredpath.co.uk/blog/decorator-pattern-with-ruby-in-8-lines.html)

There are quite a few blog posts on the net when you google for “ruby  
decorator pattern”.

About your implementation, I prefer the syntax from the post above,  
simply because it reads more natural. Other than that, yours does seem  
a viable solution (only skimmed it, but seems fine) 🙂

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![samiron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@samiron](https://www.ruby-forum.com/u/samiron)\
**Post date:** [May 9, 2010, 9:20pm UTC](https://www.ruby-forum.com/t/decorator-pattern-in-ruby-what-do-you-think-about-the-implementation/188278/3 "2010-05-09T21:20:44Z")

</div>

On 09 May 2010, at 20:54, Michael P. wrote:

> To be a bit more resilient, I’d add a check that @decorated responds  
> to the method before sending, and then call super to let Rails get on  
> with any of its magic that you might be fubaring otherwise.

Agreed.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![samiron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@samiron](https://www.ruby-forum.com/u/samiron)\
**Post date:** [May 10, 2010, 8:20am UTC](https://www.ruby-forum.com/t/decorator-pattern-in-ruby-what-do-you-think-about-the-implementation/188278/4 "2010-05-10T08:20:55Z")

</div>

Hello Peter and Michael,  
Thanks for your comments. Keep tuned up with my blog. I will be  
investigating on more design patterns to implement in Ruby (not in  
Rails style) 😃 and of course need to thoughts to share.

Samiron paul

> **[Small Talk](https://samironpaul.blogspot.com/)**

---

<div class="post-metadata">

**Author:** ![samiron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@samiron](https://www.ruby-forum.com/u/samiron)\
**Post date:** [May 9, 2010, 8:56pm UTC](https://www.ruby-forum.com/t/decorator-pattern-in-ruby-what-do-you-think-about-the-implementation/188278/5 "2010-05-09T20:56:09Z")

</div>

On 9 May 2010 19:39, Peter De Berdt [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> About your implementation, I prefer the syntax from the post above, simply  
> because it reads more natural. Other than that, yours does seem a viable  
> solution (only skimmed it, but seems fine) 🙂

It’s an interesting pure Ruby implementation, but it’s not a great  
Rails implementation, because it’s overloading “method\_missing”  
without a call to super.  
To be a bit more resilient, I’d add a check that @decorated responds  
to the method before sending, and then call super to let Rails get on  
with any of its magic that you might be fubaring otherwise.
