Skip to content

Instantly share code, notes, and snippets.

@itsthatguy
Created January 5, 2017 17:23
Show Gist options
  • Save itsthatguy/db43b4ac4f4695674c015566ebee6dd2 to your computer and use it in GitHub Desktop.
Save itsthatguy/db43b4ac4f4695674c015566ebee6dd2 to your computer and use it in GitHub Desktop.
def conditional_names(*args)
# puts params.is_a?(String)
classes = []
args.each do |arg|
classes << arg if arg.is_a?(String)
if arg.is_a?(Array)
classes << conditional_names(*arg)
end
if arg.is_a?(Hash)
arg.each do |key, value|
classes << key if value
end
end
end
classes.reject(&:empty?).join(' ')
end
puts conditional_names('my-thing', {
enabled: 1+1 == 2,
disabled: 1+1 == 3
}, ['butts', 'dud', {foo: true, bar: false}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment