From: Jason Lillywhite Date: 2008-08-14T05:05:58+09:00 Subject: Re: changing an instance variable Sebastian Hungerecker wrote: > Jason Lillywhite wrote: >> What if I want to redefine @x inside method "foo" but only in there? > > Why? > The reason is because I have big, long algorithms inside these methods 'foo' and 'bar' and I don't want to re-write "@z = @x + @y" when I get to method 'bar'. I need to evaluate the function inside 'bar' with all the same variables except for @x. that one variable needs to be different when I run bar. Maybe I have to do this: def initialize(x, y) @x, @y = x, y end def foo @z = @x + @y end def bar(new_x) @z = new_x + @y @z * 2 end ??? - Please note that my algorithms are much larger so efficiency is my friend in this case. Thank you! -- Posted via http://www.ruby-forum.com/.