-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Adds Char#swapcase and String#swapcase instance methods. #2805
Adds Char#swapcase and String#swapcase instance methods. #2805
Conversation
To compliment #upcase and #downcase. Examples: "a".swapcase # => "A" "Cats".swapcase # => "cATS"
What are the usecases? Also, I'd call it |
Mmh, I haven't used |
Then again, even Python has a |
I was just porting some Ruby code to Crystal that used The name is for Ruby equivalence (http://ruby-doc.org/core-2.2.0/String.html#method-i-swapcase). |
Can you link/show the Ruby code? |
Original gist: https://gist.github.com/lpar/1031933 |
Well, there's no need for |
Yes, obviously the linked code isn't great code, that's not really the point. There are so many different ways to write that, we could go on about it all day. In porting the concept over I just happened to notice that a simple Ruby function wasn't available in Crystal and took the few minutes to add it. People are coming to Crystal from Ruby and I thought it would be nice to have that additional singular point of compatibility. Feel free to accept or reject, it's your language, I don't feel strongly enough either way to continue this. |
I also can't find a strong use case for this. Searching in Google and GitHub I found two use cases:
Given that the implementation is trivial (at least seeing the string as ASCII) and that it's unlikely to change in the future, I wouldn't mind including it in the standard library. At least it doesn't bother. |
A note: the linked code mutates a String, so that will anyway fail to compile and you'll have to do it in a different way... though maybe it would be nice to have a String method to replace a char or a string at a given position/range with another char/string/object. Ruby uses |
|
👍 |
Since #3560 is merged this PR should take care of passing |
I don't think there's a strong use case for this, so I'm closing this. |
To compliment
#upcase
and#downcase
.Examples: