Created
January 5, 2017 17:23
-
-
Save itsthatguy/db43b4ac4f4695674c015566ebee6dd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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