From: "Bartosz DziewoƄski" Date: 2011-10-11T23:17:15+09:00 Subject: Re: why does `a + f b` not parse? Yes, I think we all know that; the question is, why does 2 + sqrt(5) parse, but 2 + sqrt 5 does not? I've been wondering this myself - is that syntax somehow ambiguous? 2011/10/11, jake kaiden : > Phillip Gawlowski wrote in post #1026042: > >> (remember: + is a method, not an operator!) >> >> That this is a mathematical expression is coincidental > > this is a very important point in ruby... `+` is a method (and not an > operator, as Phillip pointed out,) that behaves differently with various > classes, including but not limited to Integers, Strings, and Arrays - > check out the following... > > > irb(main):001:0> p 2 + 5 > 7 > => nil > irb(main):002:0> p "two" + "five" > "twofive" > => nil > irb(main):003:0> a1 = ["one", "two", "three"] > => ["one", "two", "three"] > irb(main):004:0> a2 = [4, 5, 6] > => [4, 5, 6] > irb(main):005:0> p a1 + a2 > ["one", "two", "three", 4, 5, 6] > => nil > > > - j > > -- > Posted via http://www.ruby-forum.com/. > > -- -- Matma Rex