Class: Array
Overview
Defines rh_clone for Array
Instance Method Summary collapse
-
#rh_clone ⇒ Object
return an exact clone of the recursive Array and Hash contents.
Instance Method Details
#rh_clone ⇒ Object
return an exact clone of the recursive Array and Hash contents.
-
Args :
-
Returns :
-
Recursive Array/Hash cloned.
-
-
Raises : Nothing
examples:
hdata = { :test => { :test2 => { :test5 => :test,
'text' => 'blabla' },
'test5' => 'test' },
:array => [{ :test => :value1 }, 2, { :test => :value3 }]}
hclone = hdata.rh_clone
hclone[:test] = "test"
hdata[:test] == { :test2 => { :test5 => :test,'text' => 'blabla' }
# => true
hclone[:array].pop
hdata[:array].length != hclone[:array].length
# => true
hclone[:array][0][:test] = "value2"
hdata[:array][0][:test] != hclone[:array][0][:test]
# => true
415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/rh.rb', line 415 def rh_clone result = [] each do |value| begin result << value.rh_clone rescue result << value end end result end |