Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/core_ext/hash.rb
Overview
Nabbed, www.ruby-forum.com/topic/149449
Instance Method Summary collapse
-
#slice(keys = []) ⇒ Object
Returns a new hash with only the given keys.
Instance Method Details
#slice(keys = []) ⇒ Object
Returns a new hash with only the given keys.
5 6 7 8 9 10 11 12 |
# File 'lib/core_ext/hash.rb', line 5 def slice(keys = []) h = {} keys.each do |key| raise IndexError if self[key].nil? h[key] = self[key] end h end |