Patrick Doyle
10/21/2008 12:20:00 PM
[Note: parts of this message were removed to make it a legal post.]
On Tue, Oct 21, 2008 at 3:23 AM, Zhenning Guan <g.zhen.ning@gmail.com>wrote:
> 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?
> they'are different? which is your choose?
>
I asked this same question just a couple of weeks ago. The answers I was
given were:
Method 2:
1) Saves some typing
2) Has a slightly different mechanism for looking up class constants, which
99.99% of the time won't be noticed.
Other than that there are no differences between methods 1 & 2.
--wpd