From: G Brandon Hoyt Date: 2010-09-23T20:30:11+09:00 Subject: Re: to make dot method dot method work? On 09/23/2010 05:17 AM, Pen Ttt wrote: > here is the class > class Mycompute > def initialize(str) > @str=str > end > def values > @@result=@str > end > def up > @@result.upcase > end > end > irb(main):012:0> Mycompute.new("Abc").values > => "Abc" > irb(main):013:0> > irb(main):014:0* Mycompute.new("Abc").up > => "ABC" > irb(main):015:0> Mycompute.new("Abc").values.up > NoMethodError: undefined method `up' for "Abc":String > from (irb):15 > from :0 > > would you tell me how to fix it to make > Mycompute.new("Abc").values.up output "ABC"? The most obvious way I see to do it is to use an object attribute instead of a class attribute. in other words, @result instead of @@result. Is there a reason why you want to use a class attribute in this instance? A class attribute is not an attribute of the object.