Topic: Preserve ruby variable value

For the following code:

def mofidy list
  list = sub!(/\.\w+$/, '')
end

list = "abc.html"
modify(list)
puts list

Now list value is changed. Is there anyway to store the value of list first without modifying the modify function?
I tried:

temp = list

but it wont work, simply because all ruby variables are object.

Last edited by Shanison (2010-02-28 23:48:14)

Re: Preserve ruby variable value

Hi,

Try:

temp = String.new(list)

Re: Preserve ruby variable value

Or use dup:

temp = list.dup

It creates a duplicate smile

Rob Anderton
TheWebFellas