Ruby 1.8.0-9 Problem

K

Kevin Ethridge

--0-1120296897-1058884260=:38363
Content-Type: text/plain; charset=us-ascii

Shouldn't there be a warning or error message when try to concatenate a number in this manner?

name = "John Doe"
print "Your name is " << name.length << " characters long."

outputs:

Your name is  characters long.


--0-1120296897-1058884260=:38363
Content-Type: text/html; charset=us-ascii

<DIV>Shouldn't there be a warning or error message when try to concatenate a number in this manner? </DIV>
<DIV>&nbsp;</DIV>
<DIV>name = "John Doe"</DIV>
<DIV>print "Your name is " &lt;&lt; name.length &lt;&lt; " characters long."</DIV>
<DIV>&nbsp;</DIV>
<DIV>outputs:</DIV>
<DIV><FONT color=#0000ff size=2>
<P>Your name is  characters long.</P></FONT></DIV>
--0-1120296897-1058884260=:38363--
 
T

ts

K> Shouldn't there be a warning or error message when try to concatenate a
K> number in this manner?

svg% ri String#<<
-------------------------------------------------------------- String#<<
str << aFixnum -> str
str << anObject -> str
------------------------------------------------------------------------
Append---Concatenates the given object to str. If the object is a
Fixnum between 0 and 255, it is converted to a character before
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
concatenation.
a = "hello "
a << "world" #=> "hello world"
a << 33 #=> "hello world!"
a #=> "hello world!"

svg%


Guy Decoux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top