Skip to content

Commit

Permalink
Simplify merge block behavior
Browse files Browse the repository at this point in the history
Also, add explicit error for weird cases
  • Loading branch information
rwz committed Oct 31, 2014
1 parent 086a011 commit 4503162
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/jbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,14 @@ def _merge_values(current_value, updates)
elsif _blank?(current_value) || updates.nil?
updates
elsif ::Array === updates
current_value = ::Array === current_value ? current_value.dup : []
current_value.concat updates
::Array === current_value ? current_value + updates : updates
elsif ::Hash === current_value
current_value.merge(updates)
else
current_value = current_value.dup
current_value.update updates
raise "Can't merge #{updates.inspect} with #{current_value.inspect}"
end
end


def _write(key, value)
@attributes = {} if _blank?
@attributes[_key(key)] = value
Expand Down

0 comments on commit 4503162

Please sign in to comment.