2009/5/22 Markus S. email@example.com:
url << (options.delete(:protocol) || 'http')
@b = opts.delete(:b) || “b”
raise “unkown options: %s” % opts.keys.inspect unless opts.empty?
You can have that with the non deletion approach as well.
I agree to what Robert said: this should be carefully inspected.
Generally I would refrain from changing an argument, especially if it
is some global options object. These options might be needed in other
places as well and if they are modified by code other than the option
parsing (or reading) process then chances are that something will
break. For example, consider two places in code which need to react
on the same option value then only one of them gets the value with the
“delete pattern” and even worse, things may accidentally work
initially but break if initialization order is changed.
Also, if the options instance is frozen after being filled by option
parsing or reading process the delete approach won’t work any more.
As a general rule of thumb it is safer to not modify option arguments.