assert_valid_keys(*valid_keys)
Instance Public methods
Validate all keys in a hash match *valid_keys
, raising
ArgumentError on a mismatch. Note that keys are NOT treated indifferently,
meaning if you use strings for keys but assert symbols as keys, this will
fail.
{ name: 'Rob', years: '28' }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key: :years. Valid keys are: :name, :age" { name: 'Rob', age: '28' }.assert_valid_keys('name', 'age') # => raises "ArgumentError: Unknown key: :name. Valid keys are: 'name', 'age'" { name: 'Rob', age: '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing
Please login to continue.