sonic-pi

https://github.com/sonic-pi-net/sonic-pi

C++

Code. Music. Live.

Hash#assert_valid_keys

Validate all keys in a hash match <tt>*valid_keys</tt>, 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

Source | Google | Stack overflow

Edit

git clone [email protected]:sonic-pi-net/sonic-pi.git

cd sonic-pi

open app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/hash/keys.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Hash-assert_valid_keys-for-pr


# Commit to git

git add app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/hash/keys.rbgit commit -m "better docs for Hash#assert_valid_keys"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Hash-assert_valid_keys-for-pr

hub pull-request


# Celebrate!