From: Sarah Allen Date: 2010-04-15T05:30:33+09:00 Subject: Re: I thought spaces didn't matter around operators Sarah Allen wrote: > But, I still can't fully answer my original question > >>> 1 + 1 > is the same as >>> 1.send(:+, 1) > >>> 1 +1 > is the same as...? >>> 1 1.send(:+@) > SyntaxError: compile error > (irb):8: syntax error, unexpected tINTEGER, expecting $end > 1 1.send(:+@) > ^ > from (irb):8 > > nope. I still don't quite get the answer to the above question, but the rest of my post was incorrect. >>> t = Time.now > => Wed Apr 14 12:46:30 -0700 2010 >>> 1 +t > TypeError: Time can't be coerced into Fixnum > from (irb):19:in `+' > from (irb):19 This fails because 1 + Time.now doesn't work either. Fixnum's + method requires a Fixnum parameter. Someone on suggested that the unary operator is only used if there isn't an object that precedes the operator. However, if that were true, Time.now -t would work. A special case for String and Fixnum? >> "foo" +"bar" => "foobar" >> 1 +1 => 2 >> 1 -1 => 0 >> Time.now - Time.now => 0.0 >> Time.now -Time.now NoMethodError: undefined method `-@' for Wed Apr 14 13:28:15 -0700 2010:Time from (irb):40 Still curious, Sarah -- Posted via http://www.ruby-forum.com/.