From: "cardboard42@..." Date: 2007-07-26T00:44:59+09:00 Subject: Re: A question of style... On Jul 25, 11:38 am, "cardboar...@gmail.com" wrote: > On Jul 25, 11:06 am, "Kyle Schmitt" wrote: > > > > > I just had a funny thing happen. > > I've got a bunch of classes that take a url for their initialize > > methods, and do a little cleaning on the url, just in case. > > > I was setting them all up like this > > @url = "http://localhost:1948/" > > @one = pageOne(@url) > > @two = pageTwo(@url) > > @three = pageThree(@url) > > > Because of the housekeeping & pass-by-reference being standard, @url > > ended up getting longer and longer, and strange and stranger. > > > I know a dozen fairly easy ways of solving this problem, but my > > question is, what is the _right_ way to solve it in ruby? > > > I could easily do this in the SuperPage class that all the pages > > inherit from, but it seems a tad awkward. Then again so do some of > > the other ideas I have. > > > def initailize(url) > > @url=cleanURL(url.clone) > > end > > > Thanks, > > Kyle > > I think it's more standard to use String#dup rather than clone. If all > these pages have access to the cleanURL method why not just do the dup > in there rather than passing in the copy? > > Ken Oh yeah and the rubyish way to do the dup in cleanURL would be like so def cleanURL(url) url = url.dup ... And then you can continue on your merry way like nothing changed. Ken