I suspect that having no space after the + makes Ruby think it is a
unary operator.  And since to_s is a method, Ruby thinks that you're
passing +'bar' to x.to_s.  This can't be the only problem, though,
since it is giving you a SyntaxError before it actually complains about
passing an unexpected argument to to_s...

    David

On Jan 19, 1:52 pm, "Paul" <tester.p... / gmail.com> wrote:
> I just found what looks like a bug in Ruby 184-20. (I haven't tried it
> in newer builds.)  Here's a simple script that will expose this bug:
> ----
> irb(main):001:0> x = 1
> => 1
> irb(main):002:0> puts 'foo' + x.to_s +'bar'
> SyntaxError: compile error
> (irb):2: syntax error
> puts 'foo' + x.to_s +'bar'
>                      ^
>         from (irb):2
> ----
>
> I finally figured out that it was the Plus sign *right next* to the
> "bar", *after* the "to_s" method that Ruby dislikes.  If I insert a
> space, I get the correct output.  If I take out both spaces, I get the
> correct output.  It's only if there's a space after the "to_s" and none
> between the Plus sign and string-in-quotes that it blows up.
>
> That is:
>
> > puts 'foo' + x.to_s + 'bar'     # this works
> > puts 'foo' + x.to_s +'bar'      # doesn't work
> > puts 'foo' + x.to_s+ 'bar'      # this works
> > puts 'foo' + x.to_s+'bar'       # this worksAnyone know why this might be?  I haven't played with it anymore, so I
> wonder if this bug exists with other methods.
> 
> Paul