From: Eric Hodel Date: 2006-11-17T16:39:57+09:00 Subject: Re: case vs using if question On Nov 16, 2006, at 11:07 PM, Scott Comboni wrote: > I need to parse the syntax on files based on a two charcter code > such as > PC which would return a value like this PC = Postcard I have many > many > codes and Im very new to Ruby and not sure what the best way to do > this > is and performance considerations? Benchmark and profile to find performance considerations. > So would multiple if statements be a better ruby way then using > case or does it mater? Use multiple if statements when the comparisons are different. Use a case statement when one side of the comparison is always the same or when exploiting #=== will make your code simpler. But see also the Hash solution for when you're using a case for a map. That's even cleaner and simpler than a big case statement. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com