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!

Super simple ruby decorators

I wanted to have model decorators, accessible from anywhere but in separate namespace.

https://gist.github.com/dux/581c860c143ffb17da0037e14159cb43

Comments

if somebody uses https://github.com/drapergem/draper or something similar I would appreciate comment when and why alternate approach better, if it is.

I personally prefer plain old decorators:

https://gist.github.com/yukas/7d68738c33a5aece045885fbe6394466

— No magic thus no bugs — Easy to test — We can have number of decorators for different purposes

One thing I found lacking with various decorator implementations is that they always fall back to method missing for every method call.

The following example attempts optimizes the class by defining the method the first time method missing is called for a method that the decorated object responds to.

https://gist.github.com/dkolath/c306b6e72f6109dda49e91c7323382af

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