From: Rob Biedenharn Date: 2008-04-25T03:11:29+09:00 Subject: Re: Function appends same value to string based on number of function calls On Apr 24, 2008, at 2:00 PM, vannuys@gmail.com wrote: > Hi Guys, > > Is this default ruby behaviour or is this a bug? Based on the number > of call to Testappend::get_some_value, the string "-New Value" is > appended x number of times. If you first assign value = '' instead of > value = @text, the behaviour is different and the "-New Value" string > is appended only once. Do you mean: def get_some_value value = '' value << '-New Value' return value end If so, where do you do anything with the String object to which @text refers? BTW, you could simplify your original to just: def get_some_value @text << '-New Value' end -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com > version of ruby: ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux] > > Thanks. > > Philippe > > ----------------------------------------------------- > > module ATest > > def ATest.main > > t = TestAppend.new > puts t.get_some_value ==> Start of string-New Value > puts t.get_some_value ==> Start of string-New Value-New Value > puts t.get_some_value ==> Start of string-New Value-New Value-New > Value > > end > > class TestAppend > attr_accessor :text > > def initialize(attributes = {}) > @text = "Start of string" > end > > def get_some_value > value = @text > value << '-New Value' > return value > end > > end > > end > > ATest::main >