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

Do not suggest #name= for #name and vice versa #180

Merged
merged 2 commits into from Dec 5, 2022

Conversation

mboeh
Copy link
Contributor

@mboeh mboeh commented Nov 30, 2022

A recent discussion on Hacker News reminded me of a particular type of suggestion that seems always irrelevant and potentially confusing. That would be suggesting #foo when someone calls obj.foo = 1 or #foo= when someone calls obj.foo. I have actually seen inexperienced Rubyists read the message, scratch their heads, and try obj.foo(1) before moving on to their next idea.

Example:

3.1.2 :005 > book.title = "Programming Ruby"
(irb):5:in `<main>': undefined method `title=' for #<Book:0x00007f6b8842d650> (NoMethodError)
Did you mean?  title      

This is a fairly brute force implementation -- if the missing method name ends with =, only suggest methods that do, and vice versa. A more nuanced approach would be just to exclude the exact method name with = added or removed, as the case may be. I'm happy to spend some more time on it if the general proposal is welcome.

Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
@yuki24
Copy link
Member

yuki24 commented Dec 5, 2022

LGTM, thank you!

@yuki24 yuki24 merged commit 0516931 into ruby:master Dec 5, 2022
matzbot pushed a commit to ruby/ruby that referenced this pull request Dec 5, 2022
(ruby/did_you_mean#180)

* Do not suggest #name= for #name and vice versa
* Avoid allocating unnecessary MatchData

Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants