From: Pat Maddox Date: 2006-05-16T18:14:52+09:00 Subject: Re: learn to program On 5/16/06, Tim Becker wrote: > > wuss_var is "" after major_pest returns. So apparently you can affect > > it. The only way (that I know of) to write that method without > > affecting the outside variable is > > > > def major_pest(wussy_var) > > guardian_angel = wussy_var.clone > > guardian_angel.slice!(0..-1) > > puts "HAHA! I ruined your variable!" > > end > > the reason that ruins your variable is that `slice!` modifies the > object in place (this is why it ends in an `!`). I understand that...what I don't necessarily understand is why wuss_var is "" outside of the method. If they really have no interaction, then I wouldn't expect it to change. If you do: > > > def major_pest(wussy_var) > > wussy_var=wussy_var.slice(0..-1) > > puts "HAHA! I ruined your variable!" > > end > > instead you don't change the original object, instead slice creates > the clone for you. My real issue is with the excerpt from the book, which would make new programmers think they can do whatever they want to an object inside a method and not have it affect anything outside of it. Clearly that is not the case. Pat