From: Mike Stok Date: 2006-09-11T01:50:57+09:00 Subject: Re: patching strings together to make a variable On 10-Sep-06, at 11:52 AM, Sy Ali wrote: > On 9/10/06, David Vallner wrote: >> > ab = "pass" >> > puts ("a" + "b").to_variable >> >> This sounds very, very PHP to me. And subjectively speaking, I think >> variable variables from that language are the worst abomination in a >> structured programming language since VB goto. >> >> Does that really make code clearer instead of just "clever"? > > I know nothing of PHP, but this trick would make my code much clearer. > With David.first's recommendation of instance_variable_get I can > re-use blocks of code much more intelligently. > > Previously, I've been duplicating methods and just renaming a single > variable.. (just to ensure that method1 works the same as method2) a > variation of this would be cleaner I think. > > My code is still quite hackish, so it's likely that I'll figure things > out in some time, and will be able to evolve towards even cleaner > code, perhaps dropping this trick. What are you actually trying to do? Sometimes stepping back from a particular obstacle can give a fresh point of view which sometimes leads to "nicer" code. Mention of duplicating methods and renaming a single variable hints strongly there may be more ways to skin this cat. Mike -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply.