Get the latest tech news

Build a minimal decorator with Ruby in 30 minutes


A while ago, I needed to add some view-related instance methods to a model. Decorators are my go-to pattern to handle this kind of logic. So, I built a minimal decorator from scratch, added a bunch of extra behaviors, only to end up abstracting all of that away. Follow along!

So I built a minimal decorator from scratch, added a bunch of extra behaviors, only to end up abstracting all of these away. When I can call teacher.colour_coded_availability in my views, the method retrieves a CSS class and adds it to the HTML<td> tag. I can create an ApplicationDecorator whose job is to handle instantiation, and forwarding method calls to the underlying record.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of minutes

minutes

Photo of ruby

ruby

Photo of minimal decorator

minimal decorator

Related news:

News photo

EXCLUSIVE: Amazon Doubles Prime Video Ads to 6 Minutes Per Hour

News photo

Cloud brute-force attack cracks Google users' phone numbers in minutes

News photo

Everything Apple Announced at WWDC 2025 in 9 Minutes