From: Chris Gernon Date: 2006-11-03T07:18:20+09:00 Subject: Re: str1 = str2 is not a copy?!? Joe Ruby MUDCRAP-CE wrote: > WHY is var line getting changed by operations on var base_name? Isn't > 'base_name = line' supposed to create a copy? '=' in this case seems to > be acting like an alias or something. Yep. All variables in Ruby are actually references to objects ... so using the = operator actually signifies "this variable now points at the same object as that variable". What you want is probably either: base_name = line.clone or base_name = String.new(line) but it would probably make more sense to just create base_name at the first operation where you want the two to be different - for example: line.strip! puts line base_name = line.sub('www.', '') base_name.sub!(/\.\w+$/, '') puts line > BTW, is there a foreach function that automatically strips off the > newlines from line? Returning the record separators is silly. Hmmm, not that I know of. However, I just want to mention that you probably want String#chomp rather than String#strip, unless you actually want to strip whitespace from the beginning of the string as well. > Currently hating Ruby, > Joe Watch it - you may be in danger of losing your MUDCRAP certification ... ;) -- Posted via http://www.ruby-forum.com/.