Sha256: 81341f276b3f27f32c3f48f5ad062ab29f98dc49f92a6afc76b165d529772c40

Contents?: true

Size: 404 Bytes

Versions: 13

Compression:

Stored size: 404 Bytes

Contents

class Hash
  # Returns a new hash containing only the keys specified
  # that exist in the current hash.
  #
  #  {:a => '1', :b => '2', :c => '3'}.only(:a, :c)
  #  # => {:a => '1', :c => '3'}
  #
  # Keys that do not exist in the original hash are ignored.
  def only(*keys)
    inject( {} ) do |new_hash, (key, value)|
      new_hash[key] = value if keys.include?(key)
      new_hash
    end
  end
end

Version data entries

13 entries across 13 versions & 5 rubygems

Version Path
commonthread-clickatell-0.5.2 lib/core-ext/hash.rb
lookout-clickatell-0.8.3 lib/core-ext/hash.rb
clickatell-0.8.2 lib/core-ext/hash.rb
clickatell-0.8.1 lib/core-ext/hash.rb
clickatell-0.8.0 lib/core-ext/hash.rb
clickatell-ruby19-0.7.1 lib/core-ext/hash.rb
clickatell-0.7.1 lib/core-ext/hash.rb
dimiro1-clickatell-0.7.0 lib/core-ext/hash.rb
clickatell-0.7.0 lib/core-ext/hash.rb
clickatell-0.6.0 lib/core-ext/hash.rb
clickatell-0.4.1 lib/core-ext/hash.rb
clickatell-0.5.0 lib/core-ext/hash.rb
clickatell-0.4.0 lib/core-ext/hash.rb