From: Rob Biedenharn Date: 2010-04-15T05:20:47+09:00 Subject: Re: I thought spaces didn't matter around operators On Apr 14, 2010, at 3:47 PM, Sarah Allen wrote: > Brian Candler wrote: >> -@ is the unary minus method, +@ is the unary plus method. >> >> class Foo >> def -@ >> "Minused" >> end >> def +@ >> "Plussed" >> end >> end > > This is a very helpful example. > > 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. > > So, in what way is 1 +2 not like 1 +t (where t is a Time object). I > know > 2 is a FixNum, but why is that significant? Specifically, how is the > expression evaluated to make 1 +1 work? From your original, Time.now -t now is a method call 1 -t 1 is not a method call > >>> t = 2 > => 2 >>> 1 +t > => 3 >>> 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 There's no coerce method for a Time instance. Try this: t = Time.now 1 + t Then do: class Time def coerce(other) case other when Integer return other, self.to_i else super end end end And retry: 1 + t This is a different issue than the parser trying to apply :+@ -Rob > > > Thanks! > Sarah > -- > Posted via http://www.ruby-forum.com/. > Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com