Topic: Why options.delete(:my_option) instead of options[:my_option]?

I have noticed in lots of gems and Rails code, that methods normally call Hash#delete to get an option, instead of just using Hash#[].
This seems to be the standard pattern for getting an option.

1. But why and how did it come about?

2. Is there a reason why they want to mutate the options hash that I'm too stupid to figure out?

The only reason I can think of, is for performance reasons, in that the next search of the hash will have less keys to look at.

Thanks,
Jonathan

Re: Why options.delete(:my_option) instead of options[:my_option]?

OK, I spotted a reason. I found a helper method that builds a link. One of its parameters is an options hash. This hash is passed to the link_to method. But as it has a key that is not understood by the link_to method, the code uses delete to remove the key-value.

However, I suspect there's lots of code out there that has no need of modifying Hash arguments.