Skip to content
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

Merged
merged 1 commit into from
Mar 12, 2018
Merged

Conversation

Bialogs
Copy link
Contributor

@Bialogs Bialogs commented Feb 13, 2018

Closes #75

@@ -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
Copy link
Owner

@lucascaton lucascaton Feb 13, 2018

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that makes sense.

Copy link
Contributor Author

@Bialogs Bialogs Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucascaton

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.

@Bialogs
Copy link
Contributor Author

Bialogs commented Mar 12, 2018

@lucascaton Hello just wanted to ask for a status update on this. Thanks!

@lucascaton lucascaton merged commit d3ee5c8 into lucascaton:master Mar 12, 2018
@lucascaton
Copy link
Owner

@Bialogs, I've just noticed that you updated your commit. Thanks again for your PR :)

@lucascaton
Copy link
Owner

@Bialogs, version 1.70 released!
https://github.com/lucascaton/enumerate_it/releases/tag/v1.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants