Extract Method can be used when you have several expressions, a code fragment, that can be grouped together. Even if there is one expression that could be better explained with a well thought out method name, it’s still a good move.

Let’s use Extract method on the Invoice#print method:

Let’s take a look at a simple way to add clarity to your ruby methods. Extract Variable or Introduce Explaining Variable, it’s probably one of the least invasive refactoring methods. Don’t let the simplicity fool you though, any clarity or explicitness gained is well worth the change.

Use Extract Variable…

Jon Lunsford

Engineer @convertkit, programming enthusiast, father, and musician

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store