Is there a logical explanation for this? 1.to_s+"1" => "11" 1.to_s+ "1" => "11" 1.to_s + "1" => "11" 1.to_s +"1" => test.rb:2: undefined method `+@'' for "1":String (NoMethodError) bogdan _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Bogdan Ionescu wrote:> Is there a logical explanation for this? > > 1.to_s+"1" => "11" > 1.to_s+ "1" => "11" > 1.to_s + "1" => "11" > 1.to_s +"1" => test.rb:2: undefined method `+@'' for "1":String > (NoMethodError)i think the + operator can not be applied to a string. only to a number. what are you trying to do? you can do a = +1 but a = +"1" makes no sense to me
Bogdan Ionescu wrote:>Is there a logical explanation for this? > >1.to_s+"1" => "11" >1.to_s+ "1" => "11" >1.to_s + "1" => "11" >1.to_s +"1" => test.rb:2: undefined method `+@'' for "1":String >(NoMethodError)When a and b are both strings. Then a + b means: Call method ''+'' (binary plus) in string a and give b as parameter a +b means: Call method ''+@'' (unary plus) on string b which doesn''t exist +1 is the positive number 1, -1 is the negative number -1, but what should +"some string" mean? So it is not defined. Jochen -- Jochen Topf jochen-VkTBmBTYYDUdnm+yROfE0A@public.gmane.org http://www.remote.org/jochen/ +49-721-388298
Nothing really, I ommited typing a space and that resulted into an exception which eventually I tracked down to that. On 11/19/05, Simon Santoro <Simon.Santoro-Syd3ARw+vPY@public.gmane.org> wrote:> > Bogdan Ionescu wrote: > > Is there a logical explanation for this? > > > > 1.to_s+"1" => "11" > > 1.to_s+ "1" => "11" > > 1.to_s + "1" => "11" > > 1.to_s +"1" => test.rb:2: undefined method `+@'' for "1":String > > (NoMethodError) > > i think the + operator can not be applied to a string. only to a number. > what are you trying to do? > > you can do > a = +1 > > but a = +"1" makes no sense to me > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks, I got it. bogdan> > +1 is the positive number 1, -1 is the negative number -1, but what > should +"some string" mean? So it is not defined. > > Jochen > -- > Jochen Topf jochen-VkTBmBTYYDUdnm+yROfE0A@public.gmane.org http://www.remote.org/jochen/ +49-721-388298 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails