I have a a function which looks like this:
def rename(basename: true, extension: '.txt') ...
I have a configuration hash, e.g.
config = {basename: false, extension: '.pdf', offset: 10, something:
'else'}
I want to call the function:
rename(**config)
but clearly this doesn't work because some arguments are specified, e.g.
:offset which are not included in the function. One way to deal with this
is:
def rename(basename: true, extension: '.txt', **options) ...
but I'm not sure I'm happy with this since it might mean that if the
definition of rename changes, some configuration options that shouldn't be
provided suddenly become meaningful (and/or do the wrong thing).
So, I'd like to make a sub-hash, e.g.
Hash[[:basename, :extension].collect{|key| [key, config[key]]}]
but I'm not sure if this is the best approach either. It seems sort of
clumsy. It would be nice if there was a method like config.select(keys) or
something similar, but I couldn't find this.
Does anyone have any suggestions or ideas about what to do here? Thanks.