[Wtr-general] OT - Bug in Ruby with adding strings?

Paul Carvalho tester.paul at gmail.com
Fri Jan 19 16:26:43 EST 2007


I just found what looks like a bug in Ruby.  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 works


Anyone know why this might be?  Is there a proper place where I might pass
this information on? (I'm not on any other Ruby groups right now.)
I haven't played with it anymore, so I wonder if this bug exists with other
methods.

I'll try to remember to be consistent with my spaces moving forward.
Thought some of you might be interested.

Cheers.  Paul C.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20070119/92c90623/attachment.html 


More information about the Wtr-general mailing list