I want to change the default arguments passed to a Ruby function. For example, instead of each time writing
[1,2,3].do_stuff(:option => ' my option ')
I want to modify the defaults so that I can write
[1,2,3].do_stuff
What is the simplest, cleanest, most Ruby-like way of changing default parameters?
I like to use
superfor this. It allows us to add some functionality to the method apart from just changing default arguments:Result:
UPDATE: Removed reverse_merge! dependency. (Now looking for a better alternatives to using []= method)