> Did you mean? name
Is that the best they could do to express that `person.name` is readonly?
The "did you mean" part especially is really where they could add info that would make sense to a human, but clearly that didn't happen.
> Did you mean? name
Is that the best they could do to express that `person.name` is readonly?
The "did you mean" part especially is really where they could add info that would make sense to a human, but clearly that didn't happen.
It could be improved--not easily; a setter method does not necessarily have to map to a data type, and Ruby itself doesn't know what you mean here because the Data type is in the stdlib but doesn't appear to be a compiler special case--but this is a bit nitpicking, and I would perhaps gently push back on changing the error message because it's representing what you really do need to know in Ruby once you're past the level one "driving Rails" usage of Ruby. Getting an error message other than this one would obfuscate what's happening and leave me as a long-time Ruby user pretty confused.
I guess it would then also provide a better message for `attr_reader` vs `attr_accessor` usage, too, right?
`#set_table_name` was replaced by `#table_name=` in ActiveRecord, so (especially around the time this changed when you might have projects in older and newer versions) it would be a likely mistake to make. I'm reasonably certain this is not the only case where a setter existed without `=` as part of the name where later library updates changed it to one with `=` (or the other way around).
My point is that would be different, and as a rule, different is surprising and surprising is wrong.
object.attr = 1
is
object.send(:attr=, 1)
And yes, setters can take multiple arguments. They are just methods. Nothing special about them.
?> def you_are_wrong=(a)
?> a * 2
>> end
=> :you_are_wrong=
>> send(:you_are_wrong=, 24)
=> 48
However yes, the `foo.bar = 24` expressions translates to `(foo.send(:bar=, 24); 24)`.The reason is so that `foo = bar.baz = 12` works as you expects, it's absolutely not some kind of cruft or black magic.
tldr You tried to call name= on an object that has no such method defined on it. So you get...NoMethodError. name is defined, however, so you got a "is this the typo you made?" message.