Jump to content

Ruby on Rails/Getting Started/Don´t repeat yourself

From Wikibooks, open books for an open world
Previous: Getting Started/Install on Linux Index Next: Getting Started/Model-View-Controller

Don't repeat yourself

[edit | edit source]

To help to maintain clean code, Rails follows the idea of DRY, an acronym for Don't Repeat Yourself. The idea behind it is simple: whenever possible, re-use as much code as possible rather than duplicating similar code in multiple places. This reduces errors, keeps your code clean and enforces the principle of writing code once and then reusing it. This also helps lead to an API driven structure whereby internal methods are hidden and changes are achieved through passing parameters in an API fashion. For more information on DRY look at the Wikipedia article