Skip to content

Conversation

@byroot
Copy link
Member

@byroot byroot commented Dec 20, 2025

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.

@byroot byroot requested a review from a team as a code owner December 20, 2025 13:27
@BurdetteLamar
Copy link
Member

@byroot, I don't feel qualified to review.

@byroot
Copy link
Member Author

byroot commented Dec 20, 2025

@BurdetteLamar I ddin't make the request, it's automatic.

But @hsbt is in the reviewer, I think he can make that call.

@BurdetteLamar
Copy link
Member

Okay, thanks.

Copy link
Member

@st0012 st0012 left a 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)


# Output "I *LOVE* RUBY"
say['love'] = "*love*"
say = say.sub('love', "*love*")
Copy link
Member

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?

Suggested change
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.
@byroot byroot force-pushed the improve-code-sample branch from ca51af2 to b32e438 Compare December 20, 2025 15:54
Copy link
Contributor

@jeremyevans jeremyevans left a 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.

Copy link
Member

@hsbt hsbt left a 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.

@hsbt hsbt merged commit 358d73e into ruby:master Dec 20, 2025
1 check passed
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.

5 participants