# Newbie question

**URL:** <https://www.ruby-forum.com/t/newbie-question/110287>\
**Category:** Ruby\
**Created:** [July 24, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/newbie-question/110287 "2007-07-24T22:40:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ededed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@ededed](https://www.ruby-forum.com/u/ededed)\
**Post date:** [July 24, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/newbie-question/110287/1 "2007-07-24T22:40:53Z")

</div>

Hi,

Under most languages it pays to use a StringBuffer of sorts.

Is this true for Ruby, should one use a StringBuffer when appending  
many strings?

If so, what is the string buffer called for Ruby?

---

<div class="post-metadata">

**Author:** ![ededed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@ededed](https://www.ruby-forum.com/u/ededed)\
**Post date:** [July 24, 2007, 10:45pm UTC](https://www.ruby-forum.com/t/newbie-question/110287/2 "2007-07-24T22:45:15Z")

</div>

On Wed, Jul 25, 2007 at 05:40:01AM +0900, ed wrote:

> Under most languages it pays to use a StringBuffer of sorts.
> 
> Is this true for Ruby, should one use a StringBuffer when appending  
> many strings?
> 
> If so, what is the string buffer called for Ruby?

Strings are mutable in ruby so you just use the \<\< method to append to a  
string. Don’t, though, use + as that creates a new string.

‘Foo’ \<\< ‘Bar’, etc

marcel

---

<div class="post-metadata">

**Author:** ![ededed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@ededed](https://www.ruby-forum.com/u/ededed)\
**Post date:** [July 24, 2007, 10:48pm UTC](https://www.ruby-forum.com/t/newbie-question/110287/3 "2007-07-24T22:48:29Z")

</div>

On 7/24/07, ed [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> Under most languages it pays to use a StringBuffer of sorts.

Under most languages it pays to not do heinous things that cause the  
interpreter/runtime to thrash.

Knowledge is power:  
[http://whytheluckystiff.net/articles/theFullyUpturnedBin.html](http://whytheluckystiff.net/articles/theFullyUpturnedBin.html)

hth,  
-Harold

---

<div class="post-metadata">

**Author:** ![ededed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@ededed](https://www.ruby-forum.com/u/ededed)\
**Post date:** [July 24, 2007, 10:57pm UTC](https://www.ruby-forum.com/t/newbie-question/110287/4 "2007-07-24T22:57:10Z")

</div>

On Wed, 25 Jul 2007 05:43:22 +0900  
“Marcel Molina Jr.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> to a string. Don’t, though, use + as that creates a new string.
> 
> ‘Foo’ \<\< ‘Bar’, etc

Thanks, I will give that a go. My automatic knee-jerk reaction was to  
use +=, as you pointed out, looks like some more syntax to adjust to  
here!

---

<div class="post-metadata">

**Author:** ![ededed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@ededed](https://www.ruby-forum.com/u/ededed)\
**Post date:** [July 24, 2007, 10:56pm UTC](https://www.ruby-forum.com/t/newbie-question/110287/5 "2007-07-24T22:56:05Z")

</div>

On Wed, 25 Jul 2007 05:47:43 +0900  
“Harold H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [http://whytheluckystiff.net/articles/theFullyUpturnedBin.html](http://whytheluckystiff.net/articles/theFullyUpturnedBin.html)  
> Thanks very much, this looks like a very useful resource.
