Decorators in Ruby are not devils. Check it. We almost already have them! This is some sinatra code.

“`ruby

|

| without decorators

|

route = ->(matcher, methods=[:get]) { methods.each ->(method) { send(method, matcher) { yield } } }

def home erb :home end

here’s the part that would be cool as a decorator

route.call(‘/’) { home } ”`

I propose a pretty new operator: the unary bitwise or, aka “decorator”. Python uses @, which is fine, but it doesn’t look like Ruby. I think this aesthetic is more appropriate:

“`ruby

|

| with decorators!

|

route = … # same as above

| route(‘/’) def home erb :home end ”`

Behind the scenes, this is syntactic sugar - just like decorators are in python!

“`ruby | decorator(decorator_args) def method(body_args) body end

=>

def method(decorator_args) decorator.call(decoratorargs) { |*bodyargs| body } end ”`