Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_tricks.rb

Direct Known Subclasses

MagicModelsGenerator::ModelHash

Instance Method Summary collapse

Instance Method Details

#merge_with_prefix(prefix, hash) ⇒ Object



12
13
14
15
16
# File 'lib/hash_tricks.rb', line 12

def merge_with_prefix(prefix, hash)
	merged = clone
	hash.each {|key, value| merged.merge!("#{prefix}_#{key}" => value)}
	merged
end

#merge_with_prefix!(prefix, hash) ⇒ Object



18
19
20
# File 'lib/hash_tricks.rb', line 18

def merge_with_prefix!(prefix, hash)
	hash.each {|key, value| merge!("#{prefix}_#{key}" => value)}
end

#pass(*keys) ⇒ Object

lets through the keys in the argument >> => 1, :two => 2, :three => 3.pass(:one)

> :one=>1



5
6
7
8
9
10
# File 'lib/hash_tricks.rb', line 5

def pass(*keys)
  tmp = self.clone
  keys = keys[0] if keys[0].is_a? Array
  tmp.delete_if {|k,v| ! keys.include?(k) }
  tmp
end