From: Will Bailey Date: 2007-06-11T23:44:39+09:00 Subject: Re: [QUIZ][SOLUTION] Mexican Blanket (#127) ------=_Part_106983_4688750.1181573078134 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline cool...I was trying to figure out how to use %w but was missing the leading *. Now it seems like I could have just used an array. Originally I was looking at using the letters to key the colors, which is why I was thinking hash. Isn't the result of your second suggestion almost an array in hash clothing? Thanks for the tips Will On 6/11/07, James Edward Gray II wrote: > > On Jun 10, 2007, at 10:39 AM, Will Bailey wrote: > > > Any feedback on how I can improve this code would be much appreciated. > > One idea came to me on a quick glance at the code... > > > ---------------------------------------------------------------------- > > --------------------------------------- > > @colors = > > Hash > > ["0","black","1","red","2","orange","3","yellow","4","green","5","blue > > ","6","indigo","7","violet","8","white","9","grey"] > > First, you can drop a lot of punctuation from a line like this using > Ruby's word Array syntax: > > @colors = Hash[ *%w[ 0 black 1 red 2 orange 3 yellow > 4 green 5 blue 6 indigo 7 violet > 8 white 9 grey ] ] > > Of course, those keys are just indices, and we should probably treat > them as such: > > require "enumerator" > @color = Hash[ *%w[ black red orange yellow green > blue indigo violet white gray ]. > enum_with_index.to_a.flatten.reverse ] > > I do realize that's not quite as readable though. > > James Edward Gray II > > -- will bailey towers perrin 804.852.6758 ------=_Part_106983_4688750.1181573078134--