From: Brian Candler Date: 2010-09-23T22:07:42+09:00 Subject: Re: to make dot method dot method work? When you call foo.bar.baz then you are: 1. calling method 'foo' 2. that returns an object 3. calling 'bar' on the object returned from (2) 4. that returns an object 5. calling 'baz' on the object returned from (4) So: > 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" That returns a string (and sets @@result as a side-effect). > irb(main):015:0> Mycompute.new("Abc").values.up > NoMethodError: undefined method `up' for "Abc":String > from (irb):15 > from :0 Strings don't have a method called 'up' - but they do have 'upcase'. So you can do: Mycompute.new("Abc").values.upcase Or else perhaps this is what you want: obj = Mycompute.new("Abc") obj.values obj.up Or else: def values @@result = @str self end in which case Mycompute.new("Abc").values.up will work, because your values method returns the object itself, not a String. -- Posted via http://www.ruby-forum.com/.