In the ruby pickaxe book, there is a line that says
attr_accessor is a class method defined in class Module
But isn’t attr_accessor an instance method? Am I missing something here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, all documentation I can find agrees that
attr_accessoris an instance method of Module, and I believe it would have to be an instance rather than class method to do what it does.My guess is that it’s just a typo. The authors were probably just trying to point out that rather than being part of the language proper,
attr_accessorand friends are just methods of the Module class, and they accidentally said "class" rather than "instance".Update: In fact, I can’t find your quote in my copy (10th anniversary edition), although it’s print rather than PDF, so I can’t easily search it. The closest thing I can find is:
It’s quite possible that the line you quoted was edited out of editions later than yours.
Update 2: It’s officially a typo. Listed as page 382 in the errata: