Class: Hash

Inherits:
Object show all
Defined in:
lib/libciel.rb

Instance Method Summary collapse

Instance Method Details

#exists_rec?(a) ⇒ Boolean

nil safe version of Hash#[]. h.exists_rec?() is the same as h.try.send(:[],‘world’).

Returns:

  • (Boolean)


95
96
97
98
99
100
101
# File 'lib/libciel.rb', line 95

def exists_rec?(a)
	#if a.length<1 then return false
	if !self.include?(a[0]) then return nil end           #if not found
	if a.length==1 then return self[a[0]] end             #if found and last
	if !self[a[0]].is_a?(Hash) then return nil end #if not last and child not hash
	return self[a[0]].exists_rec?(a[1..-1])               #check child
end

#patch(par) ⇒ Object

Returns self.dup with overwriting par.



103
104
105
106
107
# File 'lib/libciel.rb', line 103

def patch(par)
	h=self.dup
	par.each{|k,v|h[k]=v}
	return h
end