lib/rh.rb in lorj-1.0.1 vs lib/rh.rb in lorj-1.0.2
- old
+ new
@@ -64,13 +64,14 @@
#
# # it is like searching for nothing...
# yVal.rh_lexist? => 0
def rh_lexist?(*p)
+ p = p.flatten
+
return 0 if p.length == 0
- p = p.flatten
if p.length == 1
return 1 if self.key?(p[0])
return 0
end
return 0 unless self.key?(p[0])
@@ -210,13 +211,13 @@
#
# yVal.rh_set('blabla', :test2, 'text') => :test
# # yVal = {:test2 => {:test5 => :test, 'text' => 'blabla'},
# :test5 => :test }
def rh_set(value, *p)
+ p = p.flatten
return nil if p.length == 0
- p = p.flatten
if p.length == 1
self[p[0]] = value
return value
end
@@ -258,13 +259,14 @@
#
# yVal.rh_del(:test, :test5)
# # yVal = {:test2 => {} }
#
def rh_del(*p)
+ p = p.flatten
+
return nil if p.length == 0
- p = p.flatten
return delete(p[0]) if p.length == 1
return nil if self[p[0]].nil?
self[p[0]].rh_del(p.drop(1))
end
@@ -292,11 +294,11 @@
# # :test5 => 'test' }}
# rh_key_to_symbol(4) same like rh_key_to_symbol(3)
def rh_key_to_symbol(levels = 1)
result = {}
- each do | key, value |
+ each do |key, value|
new_key = key
new_key = key.to_sym if key.is_a?(String)
if value.is_a?(Hash) && levels > 1
value = value.rh_key_to_symbol(levels - 1)
end
@@ -323,10 +325,10 @@
# rh_key_to_symbol?(1) return false
# rh_key_to_symbol?(2) return true
# rh_key_to_symbol?(3) return true
# rh_key_to_symbol?(4) return true
def rh_key_to_symbol?(levels = 1)
- each do | key, value |
+ each do |key, value|
return true if key.is_a?(String)
res = false
if levels > 1 && value.is_a?(Hash)
res = value.rh_key_to_symbol?(levels - 1)