How to organize methods in a Ruby class

Yury Kaspiarovich
1 min readJun 24, 2016

--

Although Ruby considered to be less formal more fun language, sometimes it can be helpful to be a bit more formal, a bit less fun and if it adds more clarity what’s the heck.

I usually separate public and private interface and try to arrange methods in a way that “class tells a story”.

Consider this code:

It’s not clear what methods should we use and what is the class intent. No story, just couple of separate methods.

After number of rearrangements:

Public interface shows methods that should be used which immediately reveals the class intent. Class also easy to read since all methods arranged in order they used, which makes you feel like you reading a story.

Good code reads like a well-written prose.

--

--