If attr_accessor includes an element, eg. ':name', is there any need for the '=name' method?

ساخت وبلاگ

Vote count: 0

Preface: I do understand the standard definition for attr_accessor and know that attr_accessor stands for two instance methods-a setter and a writer, and attr_accessor allows instances variables to be accessible throughout the class.

But now and then I see an element included in attr_accessor AND is defined as a method.

So my question is: Why does that happen? Is it just bad code I saw?

Pseudo/example code:

class Such_n_such attr_accessor :name, :color #code omitted def color=(color) (some code) end

Thanks in advance!

asked 1 min ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 307 تاريخ : شنبه 29 اسفند 1394 ساعت: 21:54