3 ms·
Hacking Ruby's Default Arguments
- jamesbritt 18y agoI don't quite see this as "hacking" anything, but it's a useful thing to know. Along similar lines, I was coding some Ruby and calling a method that took a flag argument. E.g. save_something @something, true and it bothered my that it was not obvious what that last value was for. I figured that one approach might be to create a throwaway variable and use it in place of the literal: overwrite_existing = true save_something @something, overwrite_existing ... and then decided to just pass that first expression in as the argument itself to tighten things up: save_something @something, overwrite_existing = true Basically, a handy (hackish?) way to document any argument.