Re: A question of style...
- From: "cardboard42@xxxxxxxxx" <cardboard42@xxxxxxxxx>
- Date: Wed, 25 Jul 2007 15:38:13 -0000
On Jul 25, 11:06 am, "Kyle Schmitt" <kyleaschm...@xxxxxxxxx> 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
.
- Follow-Ups:
- Re: A question of style...
- From: Kyle Schmitt
- Re: A question of style...
- From: cardboard42@xxxxxxxxx
- Re: A question of style...
- References:
- A question of style...
- From: Kyle Schmitt
- A question of style...
- Prev by Date: Re: read variables from string
- Next by Date: Re: read variables from string
- Previous by thread: A question of style...
- Next by thread: Re: A question of style...
- Index(es):
Relevant Pages
|
Loading