Ruby Hash.merge with specified keys only
Posted
by ba
on Stack Overflow
See other posts from Stack Overflow
or by ba
Published on 2010-05-26T08:08:13Z
Indexed on
2010/05/26
8:11 UTC
Read the original article
Hit count: 179
I'm pretty sure I saw on a Rails related site something along the lines of:
def my_function(*opts)
opts.require_keys(:first, :second, :third)
end
And if one of the keys in require_keys
weren't specified, or if there were keys that weren't specified, an exception was raised. I've been looking through ActiveSupport and I guess I might be looking for something like the inverse of except.
I like to try and use as much of the framework as possible compared to writing my own code, that's the reason I'm asking when I know how to make the same functionality on my own. :)
At the moment I'm doing it through the normal merge
routine and making sure that I have what I need with some IFs.
© Stack Overflow or respective owner