Ruby Hash#contain?(other)

Check if one hash contains another.

Usage
params.contain?(:controller=>’home’, :action=>’index’)

Code

class Hash
  def contain?(other)
    self.merge(other) == self
  end
end
Advertisements

2 thoughts on “Ruby Hash#contain?(other)

  1. I’m curious why you’re using `with_indifferent_access` here instead of just using self?

    Since with_indifferent_access is a Rails extension to the core Hash library, this would make this a a Rails Hash#contain?(other) implementation instead of a Ruby one. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s