From: Robert Dober Date: 2006-09-20T21:04:36+09:00 Subject: Re: Something strange in ruby or I'm a newbie? ------=_Part_170351_32046494.1158753872370 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 9/20/06, Jan Svitok wrote: > > On 9/20/06, Morton Goldberg wrote: > > On Sep 20, 2006, at 6:32 AM, Hussachai Puripunpinyo wrote: > > > > > Question 1: > > > > > > #IS THIS A BUG > > > class TestBug > > > def test > > > "Hello Bug" > > > end > > > end > > > class FoundBug < TestBug > > > def test > > > super +" ,I found you !" #Notice here > > > end > > > end > > > test =3D FoundBug.new() > > > puts test.test > > > > > > It blame me that > > > "undefined method `+@' for " ,I found you !":String (NoMethodError) > > > from C:/DOCUME~1/HUSSAC~1/LOCALS~1/Temp/rb1F.tmp:12" > > > Why? > > > This is bug or I miss something? > > > > > > If I replace the line in '#Notice here' to > > > > > > super+" ,I found you !" #With no space between super and my string > > > #OR > > > super + " ,I found you !" #With space both side of '+' > > > #I found that no error > > > > > > Why? > > > > No, I'm afraid it's a feature ;). if you rewrite > > > > > super +" ,I found you !" #Notice here > > > > to > > > super + " ,I found you !" #Notice space after '+'. > > > > it will work. By leaving out the space, you have invoked the unary > > '+' operator. But, of course, you wanted the binary '+' operator. In > > Ruby there are times when spaces and parentheses are critical. > > In other words, > > super +"whatever" is the same as super(+"whatever") while > super+"whatever" or super + "whatever" is the same as super(*args) + > "whatever". Impressive, well I kind of dislike it, there is a warning from ruby though right? Robert --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_170351_32046494.1158753872370--