Forum: Ruby Newbie question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0ba46e5e8e119eb34f100d6ca272e0b0?d=identicon&s=25 ed (Guest)
on 2007-07-24 22:40
(Received via mailing list)
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?
Cee0292fffa691f1fb320d5400200e99?d=identicon&s=25 Marcel Molina Jr. (Guest)
on 2007-07-24 22:45
(Received via mailing list)
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
7f891fbe8e3bae7f9fe375407ce90d9d?d=identicon&s=25 Harold Hausman (Guest)
on 2007-07-24 22:48
(Received via mailing list)
On 7/24/07, ed <ed@noreply.com> 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/theFullyUptur...

hth,
-Harold
0ba46e5e8e119eb34f100d6ca272e0b0?d=identicon&s=25 ed (Guest)
on 2007-07-24 22:56
(Received via mailing list)
On Wed, 25 Jul 2007 05:47:43 +0900
"Harold Hausman" <hhausman@gmail.com> wrote:

> http://whytheluckystiff.net/articles/theFullyUptur...
Thanks very much, this looks like a very useful resource.
0ba46e5e8e119eb34f100d6ca272e0b0?d=identicon&s=25 ed (Guest)
on 2007-07-24 22:57
(Received via mailing list)
On Wed, 25 Jul 2007 05:43:22 +0900
"Marcel Molina Jr." <marcel@vernix.org> 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!
This topic is locked and can not be replied to.