From: Christoph Rippel Date: 2000-11-23T07:37:46+09:00 Subject: [ruby-talk:6533] Re: Question about the behavior of write attributes in blocks Thank you for explanation - the output of "x".inspect() is >>"x" which made me assume that Strings are implemented as singletons (which doesn't make much sense in the presence of a replace() method). I was hoping to be able to write *********** x = [1,2,3] x.each { |i| i+= 1 } p x **************** which has the output >>[1, 2, 3] and not the ``expected'' >>[2, 3, 4] I wouldn't mind to write some thing like ******************* x = [1,2,3] x.each { |i| i.add_to 1 } p x ********************** but there is no such method for Fixnum and the only way I can think about writing such a method always involves the use of the ``=()''-operator - which means I am effectively stuck. The String Class seems to be one of the few build in classes sporting a replace() method so I can write *********** class String def add_to(n) replace((self.to_i+n).to_s) end end x = ["1","2","3"] x.each { |i| i.add_to 1 } p x ************** This gives me the indented output >> ["2", "3", "4"] This is only a stop-cap measure since I really want to manipulate Arrays (or binary trees) of Fixnum or more general any Object. Any thoughts? Christoph