RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Kansas City Ruby User Group presentation: Ryan (dot) Smith on the Decorator pattern

Ryan (dot) Smith presents on the Decorator pattern (video on vimeo) with source code for the Decorator example at github.com/ryandotsmith/decorator

Comments

OK, if that presentation had been done for another language it might have been quite good. But for ruby it’s like ignoring completly what ruby is capable of. Ruby has got a) modules and b) Object#extend which are a much nicer way to achieve the same as he does in that presentation. Additionally the code in the linked repository is rather weak. Examples: extras.inject(self.new) { |memo, extra| memo = extra.to_class.new(memo) } should really be extras.inject(self.new) { |memo, extra| extra.to_class.new(memo) }, args.empty? ? @decorated.send(method) : @decorated.send(method, args) would most likely better be args.empty? ? @decorated.send(method, *args) (doesn’t do exactly the same, but I’d say his example code in the ‘decoration’ branch doesn’t even work with his definition of Decorator#method_missing). I’m sorry to say, but IMO the whole thing is a total non-role-model.

Ok, did a fork to show what I mean: http://github.com/apeiros/

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in