Module: RubyExtension::Hash::InstanceMethods

Defined in:
lib/ruby_extension/hash.rb

Overview

module ClassMethods # :nodoc: end

Instance Method Summary collapse

Instance Method Details

#delete_keys!(*keys) ⇒ Object

delete all keys in the given array and return the new hash



28
29
30
31
32
33
# File 'lib/ruby_extension/hash.rb', line 28

def delete_keys!(*keys)
	keys.each do |k| 
		self.delete(k)
	end 
	self
end

#delete_keys_matching!(regex) ⇒ Object

delete all keys matching the given regex and return the new hash



17
18
19
20
21
22
23
24
# File 'lib/ruby_extension/hash.rb', line 17

def delete_keys_matching!(regex)
	self.keys.each do |k| 
		if k.to_s =~ Regexp.new(regex)
			self.delete(k)
		end 
	end 
	self
end

#dig(*args) ⇒ Object

params.dig(‘study_events’,se.id.to_s,‘eligible’)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_extension/hash.rb', line 36

def dig(*args)
	if args.length > 0 && self.keys.include?(args.first)
		key = args.shift
		if args.length > 0 
			if self[key].is_a?(Hash)
				self[key].dig(*args)
			else
				nil
			end
		else
			self[key]
		end
	end
end