Class: Hash

Inherits:
Object show all
Defined in:
lib/watirmark/extensions/ruby_extensions.rb

Instance Method Summary collapse

Instance Method Details

#extract(*keys) ⇒ Object Also known as: slice

Returns a hash that only contains pairs with the specified keys



46
47
48
49
50
51
# File 'lib/watirmark/extensions/ruby_extensions.rb', line 46

def extract(*keys)
  keys = keys[0] if keys[0].is_a?(Array)
  hash = self.class.new
  keys.each { |k| hash[k] = self[k] if has_key?(k) }
  hash
end