7 ms·
> But definitely could be worded much better than NoMethodError. But that is the root cause - there is no such method. The thing about 'Did you mean? name' is
by chrisseaton 4y ago
> But definitely could be worded much better than NoMethodError.
But that is the root cause - there is no such method.
The thing about 'Did you mean? name' is just a guess to help you.
- ohbtvz 4y ago> The thing about 'Did you mean? name' is just a guess to help you. And instead it throws anyone who hasn't extensive experience with Ruby's quirks into a spiral of misery.
- chc 4y agoThis is a pretty basic facet of Ruby. You do not need extensive experience to be familiar with Ruby's approach to getters and setters. This will be surprising to people whose expectations come from other languages, but I doubt it would surprise any Ruby developer.
- djur 4y agoAgreed. The second chapter of Programming Ruby, "Classes, Objects, and Variables", shows you how to manually implement 'attributes' before introducing you to the attr_* methods. This is fundamental stuff.
- bhaak 4y agoHow so? That's a day 1 experience for Ruby. Typos and calls for the methods on the wrong objects will always get you a NoMethodError. Anybody past their first Ruby tutorial will be familiar with this exception.
- deleted 4y ago[deleted]
- Karunamon 4y agoThis is the kind of problem you encounter once, scratch your head, look it up on stack overflow, understand why it is, and then commit this little quirk to memory and it never really troubles you again. (Or more realistically, your IDE underlines your error in red and you never even see the error message)
- JohnBooty 4y agoI like it because it encourages the newcomer to understand that the `=` "operator" in `foo.bar = 123` is actually just a part of a method named `bar=`. Though, to be honest, rather than an "instructive" error message... I sort of wish the language syntax itself forbade that space and simply forced you to write `foo.bar= 123` instead of `foo.bar = 123`. I wonder if Matz himself has ever second guessed that choice he made in the 90s? =)
- quesera 4y ago> I sort of wish the language syntax itself forbade that space This syntactic sugar is definitely a bit weird, but it seems necessary in the "everything is an object" design, and to simultaneously meet Ruby's prime directive of maximizing developer happiness. Can you imagine the howling from the haters if `x = 1` was a syntax error?
- maxfurman 4y agoData could implement better messaging via method_missing though, since they know any calls to a setter will fail