Skip to content

Instantly share code, notes, and snippets.

@phinze
Created February 19, 2009 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phinze/66956 to your computer and use it in GitHub Desktop.
Save phinze/66956 to your computer and use it in GitHub Desktop.
def add_css_class(original, add)
if original.nil?
return add
else
return [original, add].join(' ')
end
end
### Use Case
css_class = add_css_class(css_class, 'required') if required
### Or, better!
css_class = [css_class, 'required'].compact.join(' ') if required # thanks molgrew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment