You can do it yourself relatively easily. As mentioned in an earlier answer, half of your work is done for you in assert_valid_keys . You can flip your own method to do the rest.
def my_function( *opts ) opts.require_and_assert_keys( :first, :second, :third ) end
create lib/hash_extensions.rb with the following:
class Hash def require_and_assert_keys( *required_keys ) assert_valid_keys( keys ) missing_keys = required_keys.inject(missing=[]) do |missing, key| has_key?( key ) ? missing : missing.push( key ) end raise( ArgumentError, "Missing key(s): #{missing_keys.join( ", ")}" ) unless missing_keys.empty? end end
Finally, in config/environment.rb add this to make it work:
require 'hash_extensions'
source share