From: "Hal E. Fulton" Date: 2003-08-05T02:53:44+09:00 Subject: Re: clearing a parameter in Ruby? ----- Original Message ----- From: "Roy Patrick Tan" Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Monday, August 04, 2003 12:36 PM Subject: clearing a parameter in Ruby? > Hi, > > is it possible to write a method that can "clear" a parameter in Ruby? > That is can a write a method "push" such that for the code below: > > x = "Hello" > string_stack.push(x) > puts x > > the output will be nil instead of "Hello"? Short answer is no. Long answer is: If your parameter is something like a String or an Array, you could do a 'replace' on its contents. Likewise if it's any complex object whose state can change, you can change its state. However, assignment works on variables, not objects. In general it's impossible to write a method that knows the name of the variable passed to it, and so it's impossible to assign to the variable that was passed into the method. You can manipulate the object, but not the variable. HTH, Hal -- Hal Fulton hal9000@hypermetrics.com