From: "David A. Black" Date: 2005-07-12T19:42:07+09:00 Subject: Re: class_attr_accessor Hi -- On Tue, 12 Jul 2005 gwtmp01@mac.com wrote: > > On Jul 11, 2005, at 11:20 PM, David A. Black wrote: >> I sometimes wonder whether all the "class << self" examples obscure the >> fact that this is a general-purpose thing. In case that's the case, >> here's an example: >> >> str = "I am a string" >> class << str >> def x >> puts "method illustrating singleton class" >> end >> end > > It always seems clearer to me when written as: > > str = "I am a string" > def str.x > puts "method illustrating singleton class" > end > > I understand that the method is really defined in the > anonymous singleton class associated with str but the > 'def object.method' syntax is more self-explanatory > (to me) than the 'class <