-
Notifications
You must be signed in to change notification settings - Fork 647
Don't mutate a string literal in main code sample #3703
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
Conversation
|
@byroot, I don't feel qualified to review. |
|
@BurdetteLamar I ddin't make the request, it's automatic. But @hsbt is in the reviewer, I think he can make that call. |
|
Okay, thanks. |
st0012
left a comment
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.
I also prefer to not mutate string in the example.
(And if we still want string mutation, I feel String#sub! would better demonstrate it)
bg/examples/i_love_ruby.md
Outdated
|
|
||
| # Output "I *LOVE* RUBY" | ||
| say['love'] = "*love*" | ||
| say = say.sub('love', "*love*") |
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.
nit: I think this is the only place in the examples using single quotes. Let's use double quotes too for consistency and avoid confusion?
| say = say.sub('love', "*love*") | |
| say = say.sub("love", "*love*") |
I know this is still being debated, but as of the current version of Ruby, the first code sample does emit a deprecation warning (hidden by default but still). I think it's would be better to not mutate a string literal.
ca51af2 to
b32e438
Compare
jeremyevans
left a comment
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.
It's a little uglier, but it's more important to be correct than pretty. The idiomatic approach would be to use String#+@, but that's cryptic and not a good choice for the front page of the website.
hsbt
left a comment
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.
I agree that this is not a good example, I overlooked this code example while working.
I know this is still being debated, but as of the current version of Ruby, the first code sample does emit a deprecation warning (hidden by default but still).
I think it's would be better to not mutate a string literal.