-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support symbols/strings with spaces. #76
Conversation
lib/enumerate_it/base.rb
Outdated
@@ -116,7 +116,7 @@ def register_enumeration(values_hash) | |||
end | |||
|
|||
def define_enumeration_constant(name, value) | |||
const_set name.to_s.tr('-', '_').upcase, value | |||
const_set name.to_s.tr('-', '_').upcase.delete(' '), value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @Bialogs - how about replacing the space with a _
?
I think it'd make more sense, wouldn't it?
Something like:
...to_s.gsub(/[-\s]/, '_')...
In your example, it'd become TestEnumerationWithSpaces::SPA_CES
instead of TestEnumerationWithSpaces::SPACES
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While converting the space to _
with match /\s/
it also matches a newline. While newline is valid in a symbol, I'm not sure what your thoughts are on supporting this in the gem and wanted to let you know.
It may be out of scope for this pull request. I'm really only needing spaces in my current usage.
Therefore my recommendation is to use /\p{blank}/
match instead of /\s/
so that the same NameError: wrong constant name ...
will appear when someone uses a symbol that contains a newline.
@lucascaton Hello just wanted to ask for a status update on this. Thanks! |
@Bialogs, I've just noticed that you updated your commit. Thanks again for your PR :) |
Closes #75