Skip to content

Commit

Permalink
Merge branch 'PedroSena-array_modification_fix'
Browse files Browse the repository at this point in the history
* PedroSena-array_modification_fix:
  Fixes bug #46. recurse_over_arrays now preserve array instead of creating new w/o affecting deep_dup
  • Loading branch information
aetherknight committed Dec 19, 2016
2 parents f55cb87 + 87904eb commit 4b0a392
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/recursive_open_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ def _get_key_from_table_(name)
end

def recurse_over_array(array)
array.map do |a|
array.each_with_index do |a, i|
if a.is_a? Hash
self.class.new(a, :recurse_over_arrays => true, :mutate_input_hash => true)
array[i] = self.class.new(a, :recurse_over_arrays => true,
:mutate_input_hash => true, :preserve_original_keys => @preserve_original_keys)
elsif a.is_a? Array
recurse_over_array a
else
a
array[i] = recurse_over_array a
end
end
array
end

end
1 change: 1 addition & 0 deletions lib/recursive_open_struct/deep_dup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def deep_dup(obj, visited=[])
end
elsif obj.is_a?(Array) && @recurse_over_arrays
obj.each_with_object([]) do |value, arr|
value = value.is_a?(RecursiveOpenStruct) ? value.to_h : value
arr << value_or_deep_dup(value, visited)
end
else
Expand Down
1 change: 0 additions & 1 deletion spec/recursive_open_struct/recursion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@
end

specify "the changes show up in .to_h" do
pending "This is broken"
expect(subject.to_h).to eq({ mystery: { science: [{theatre: 9000}]}})
end
end
Expand Down

0 comments on commit 4b0a392

Please sign in to comment.