Skip to content

Instantly share code, notes, and snippets.

@afg419
Last active March 19, 2016 23:27
Show Gist options
  • Save afg419/6d13ce1b6813342d5293 to your computer and use it in GitHub Desktop.
Save afg419/6d13ce1b6813342d5293 to your computer and use it in GitHub Desktop.

I think far and away the most difficult rule to follow here would be the 4 parameters into a method rule. I think is because I've come across a variety of methods which just simply need that many parameters! The Highcharts gem had methods which could take an unlimited number of parameters (as hash options), and I often was feeding 10 - 20! A quick way around this rule is to make a simple class/struct which just has a bunch of attr_readers or methods which respond with the params you need to pass, and then pass instances of this class to the method... but that seems about the same as passing a hash with more than four key value pairs.

Another alternative might be two make a class which takes 3 parameters on initialization... and then your methods on that class could take another 3 to bring the total up to 6!

One way or another though, if you are ever going to do a sort of 'feature method' which perhaps combines a number of smaller methods to 'do the thing' the class was meant to do, this rule restricts the complexity of the feature and I don't see a way in which breaking things into smaller chunks helps with this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment