From: "Shot (Piotr Szotkowski)" Date: 2008-10-22T02:46:40+09:00 Subject: Re: what's different between self.method and class << self? --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Zhenning Guan: > we can define a instance method in lots way. > mostly, I saw people define like this: > 1. > class A > def self.class_method > #some code here.... > end > end > 2. > class A > class << self > def class_method > #some code here.... > end > end > end > the question confused me is what's the advantage of doing this in 2? You can work on the singleton=E2=80=99s properties with attr_* methods: class Example class << self attr_accessor :prop end end (With the first approach you=E2=80=99d have to define self.prop and self.prop=3D to be able to write code like Example.prop =3D 'value'.) -- Shot --=20 Damn, I need to rant, not whimper. Someone bring me a user. -- Wayne Pasc= oe --VbJkn9YxBvnuCH5J Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFI/hdDi/mCfdEo8UoRAtK1AKC+VfEbTDvXkXL8I9mAQ0o6vjXSfgCdF2XA 0iXi7Ebr2j2/WuWhkGKhnCM= =YM8Y -----END PGP SIGNATURE----- --VbJkn9YxBvnuCH5J--