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

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.
Could you please share your thoughts about this implementation?

Have a great time :slight_smile:
Take care.

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
.
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

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) :slight_smile:

Best regards

Peter De Berdt

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

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) :smiley: and of course need to thoughts to share.

Samiron paul

On 9 May 2010 19:39, Peter De Berdt [email protected] 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) :slight_smile:

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.