Concat is driving me crazy

J

Jay

This is driving me crazy. For some reason

product.title = "this is"
item.title = product.title.to_s << ' my string'

yields "this is my string"

but

product.title = "this is"
item.title = 'my string ' << product.title.to_s

will only yield "this is" without adding 'my string ' at the beginning.
I feel like there must be something incredibly simple I'm missing.
Advice would be much appreciated.
 
T

Tim Pease

This is driving me crazy. For some reason

product.title = "this is"
item.title = product.title.to_s << ' my string'

yields "this is my string"

but

product.title = "this is"
item.title = 'my string ' << product.title.to_s

will only yield "this is" without adding 'my string ' at the beginning.
I feel like there must be something incredibly simple I'm missing.
Advice would be much appreciated.

What type of objects are _prodcut_ and _title_? Most likely the
unexpected behavior is happening in these objects.

If you could post some more code that is runnable by itself and
demonstrates the unexpected behavior, then an answer might be quicker
in the coming.

Blessings,
TwP
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top