On 11/9/06, Daniel N [email protected] wrote:
than decide for yourself
Look at this for example
“he, nice, guys”.split(‘,’).map!{|x| x.strip}
“he, nice, guys”.split(“,”) ===> tmp1 ← [“he”, " nice", " guys" ]
tmp1.map!{|x| x.strip} ===> tmp2 ← [“he”, “nice”, “guys”] ** and
modifies the object referenced by tmp1 in place ***
why would you use map! ?
try to put the above expression into a context
e.g.
x = …
Hint: using map! on unreferenced objects is quite useless.
The idea was to work on the differences between xxx and xxx!
Robert, I don’t really understand what you mean. My understanding is
that
these do different things. Can I walk through this in pseudo pseudo code
to
increase my understanding;)
Excellent idea.
split the string into an unref’ed array
take the unreffed array and strip each element in place, creating a new
string at each element in the original array
which will get lost, the only thing you use is the result of the
expression, s
Total Arrays created 2
I have no idea 
How does this not differ from
“he, nice, guys”.split(‘,’).map{|x| x.strip}
“he, nice, guys”.split(“,”) ===> tmp1 ← [“he”, " nice", " guys" ]
tmp1.map!{|x| x.strip} ===> tmp2 ← [“he”, “nice”, “guys”] ***
without modifiying tmp1 inplace ***
Performance is not an issue, but I guess it is important to understand
why
one would apply map! (ignoring the existance of map would not be a good
reason)
Where, my understanding would be
split the string into an unref’ed array
take the unref’ed array, and create a new array from the result of each
element stripped.
ie. a new string object for each element put into a new array
exactly (this is done too above, it would not work else)
Total Arrays created 3
Again I have no idea 
What about
would you like to use this?
Nasty… Turns the first element (with no whitespace) into nil
No for the same reason as above why use x.strip! modifiying x when x
will
be discarded immediately? I thaught this would be the ice breaker
example

Have I understood the difference/similarities here or have I missed the
ball?
Baseball?
BTW Sometimes I get caught in the urge to explain, forgetting that
experience has shown to me that I am quite a bad teacher 
Cheers
Robert
–
The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man.