Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- app/helpers/railsstrap/navbar_helper.rb
Instance Method Summary collapse
-
#append_merge!(key, value) ⇒ Object
appends a string to a hash key’s value after a space character (Good for merging CSS classes in options hashes).
Instance Method Details
#append_merge!(key, value) ⇒ Object
appends a string to a hash key’s value after a space character (Good for merging CSS classes in options hashes)
199 200 201 202 203 204 205 206 207 208 209 |
# File 'app/helpers/railsstrap/navbar_helper.rb', line 199 def append_merge!(key, value) # just return self if value is blank return self if value.blank? current_value = self[key] # just merge if it doesn't already have that key self[key] = value and return if current_value.blank? # raise error if we're trying to merge into something that isn't a string raise ArgumentError, "Can only merge strings" unless current_value.is_a?(String) self[key] = [current_value, value].compact.join(" ") end |