From: "jay s." Date: 2011-05-27T00:00:43+09:00 Subject: Re: Method that mutates object Jeremy Bopp wrote in post #1001249: > On 5/26/2011 08:56, jay s. wrote: >> Say we wanted to write our own replace method and not use the replace >> method provided by the String class? So we want to write a method that >> takes a string object and modifies/mutates that same object and then >> returns it, without creating a copy of that object. > > What exactly are you trying to accomplish? The String class provides > multiple methods to mutate the String instance in various ways, and many > of those methods could be specified in terms of the others, including > replace. Rather than ask someone to figure out another solution to > which you may respond, "and how do we write our own method_x and not use > the method_x provided by the String class," could you provide some > details about your goals? What kind of modifications on the String > instance do you want your method to perform? What methods provided by > the String class are out of bounds (as replace apparently is)? > > To me this is sounding a bit like a homework assignment, but maybe it's > not. In any case, the documentation for the String class is actually > pretty good, so you can probably answer your own question with a little > easy reading: > > http://rdoc.info/stdlib/core/1.9.2/String > > If I understand what you're really trying to accomplish, the method you > want is definitely listed there. > > -Jeremy Just for clarification, this is by no means a homework assignment. I am new to Ruby and I'm trying to get a better grasp on how Ruby handles mutation. I actually think at this point I'll try looking at Ruby's source code and see how String#replace is implemented. Maybe I'm just over complicating my question. -- Posted via http://www.ruby-forum.com/.