S
Simon Schuster
075:0> a = "hello"
"hello"
076:0> a += " there."
"hello there."
077:0>
neat!
"hello"
076:0> a += " there."
"hello there."
077:0>
neat!
Simon said:075:0> a = "hello"
"hello"
076:0> a += " there."
"hello there."
077:0>
neat!
"*=", "/=", "&&=", "||=", and any others that I may have missed...
Axel said:Hello,
Can anybody tell me, where to find, what this means?
Thank you!
Axel
Dan said:"+=" will actually work on any class that has "+" defined, including
custom classes. I assume it is the same with "-=", "*=", "/=", "&&=",
"||=", and any others that I may have missed...
not really075:0> a = "hello"
"hello"
076:0> a += " there."
"hello there."
077:0>
neat!
I no longer have my list of web sites I learned Ruby from, but it's
pretty simple. Hope this helps.
Dan
not really
a += " there" is
a = a + " there"
a << " there"
I might be accused of premature optimizationism (A word I just made
up, I have to make an ECR.
But seriously there is just no need to pay the cost of the
construction of another String / Array.
Performance difference is already enormous for moderately long strings :
Hi --
I am not French, only my wife isDon't worry -- there's no Academie Anglaise![]()
Hmm David when one doesIt depends, though; sometimes you might want a copy, sometimes you
might definitely not. So the + vs. << decision may not be premature,
and the right decision may not even be the optimizing one![]()
I am not French, only my wife is, but it is a funny remark.
Hmm David when one does
a += b
the copy is thrown away and you have the same semantics (save some
implicit calls to to_s) as for
a << b
That is indeed an important - probably the most important - point toHi --
They're not interchangeable, though:
a = "Hello"
b = " there"
c = a
a += b
puts a # Hello there
puts c # Hello
a = "Hello"
c = a
a << b
puts a # Hello there
puts c # Hello there
Peña said:From: Dan Zwell [mailto:[email protected]]
# &&= is good for making sure a group of things are all true:
# result = true
# expressions.each {|expr| result &&= expr}
just in case you've forgotten, Dan,
expressions.all?
kind regards -botp
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.