Skip to content

Instantly share code, notes, and snippets.

View harssh-sparkway's full-sized avatar


View GitHub Profile
harssh-sparkway / dry.rb
Last active July 7, 2022 23:33
Don’t Repeat Yourself (DRY) in Ruby on Rails
#Don’t Repeat Yourself (DRY) in Ruby on Rails
#DRY (Don’t Repeat Yourself) is a principle of Software Development to reducing repetition of information or codes. We can #apply DRY quite broadly to database schema, test plan, system, even documentation. And in this post, we will take example of DRY #in Ruby on Rails development.
#In particular case, if you find some methods whose definitions are more or less similar, only different by the method name, it #may use meta programming to simplify the things to make your model more clean and DRY. Consider this simple example where we #have an article with three states.
class Article < ActiveRecord::Base