Re:Moment of Ruby: An Argument for Nothing
by the_sleaze_ on Thursday November 05, 2026 @10:17AM
(#50380163)
default arguments are a great, but I tend to advise that we cap them at 1. Too high arity is a smell.
At the same time I also understand the idea behind:
The idea would be to use something in a toggle state.I sometimes use a similar, but simpler pattern, though I also tend to use explicit method names. But for instance:
Personally I prefer the longer variants, e. g. enable_colours and disable_colours (without trailing (); if people prefer US spelling the method names could be enable_colors etc.. it is really the very same point anyway). I do, however had, also sometimes use a more generic top-level entry point such as enable. I use that for my pseudo-shell replacement for bash, written in ruby too. For instance: I mostly do this so I have an easier time remembering things; and finding a simple, ideally as simple as possible, entry point.Of course it is not exactly the same as the rails-idiom shown here, since I'd also have to use:
But I am also fine with set_colours :false. But in general I tend to prefer disable_colours in this case.Personally, since I know my brain is rather weak, I try to not use "cloaked" methods and just use oldschool setters and getters, where I treat set_foobar to be the same as foobar =.
foobar= is a bit more elegant, but I also like set_xyz in general. Oddly enough I don't really use get_xyz; but I, to my shame, must admit that I like this:
Most will omit "return_", but I kind of like stupid code where I don't have to think. In particular in bigger projects.I don't really see a need for overloading methods though. I dislike having too many instance variables however had; I noticed that when I have like more than 10 @ variables, I often find it easier to just group them into a Hash instead, with Symbols as key. So for instance:
It's not that elegant compared to: but I found a Hash to just be a lot more convenient to use here. And pp hash is super-userful. (We can easily get all instance variables programmatically, of course, but I still find a Hash structure so much more logical and convenient to use and read than many different instance variables.)