Skip to content

Instantly share code, notes, and snippets.

@polarblau
Last active December 14, 2015 23:59
Show Gist options
  • Save polarblau/5169672 to your computer and use it in GitHub Desktop.
Save polarblau/5169672 to your computer and use it in GitHub Desktop.
class Hash
def merge_html_attr!(other)
merged = self.merge(other) do |key, a, b|
if key == :class && a.is_a?(String) && b.is_a?(String)
[a, b].join(' ')
else
b
end
end
replace(merged)
end
def merge_html_attr(other)
dup.merge_html_attr!(other)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment