From: Robert Klemme Date: 2011-01-13T21:06:23+09:00 Subject: Re: Case statements - Just beautification On Thu, Jan 13, 2011 at 11:35 AM, flebber wrote: > On Jan 13, 6:41 pm, Tim Roberts wrote: >> flebber wrote: >> >I just want to clarify case statements the name after the word case is >> >this just for beautification and to help with code readability? What >> >purpose does it serve. >> >> >So in my code its "winunit" and matz's code its "birthyear". >> >> ># Method 1 - Confident - assign range >> ># number -> number >> >def pricerange(x) >> >puts "Enter the quoted price: " >> >x = gets.chomp >> >winalloc = case winunit >> >  when x == (1.50...2.50) then ... >> >  when x == (2.50...3.80) then ... >> >  when x == (3.80...5.50) then ... >> >  else something >> >end >> >> Perhaps its purpose would be clearer if you wrote it like Matz's code: >> >> x = gets.chomp >> winalloc = case x >>   when (1.50...2.50) then ... >>   when (2.50...3.80) then ... >>   when (3.80...5.50) then ... >>   else something >> end > I tough my code looked like Matz's > > Matz's code > # Case expression tests ranges with === > generation = case birthyear >             when 1946..1963: "Baby Boomer" >             when 1964..1976: "Generation X" >             when 1978..2000: "Generation Y" >             else nil >             end > My Code - (...) are placeholders > x = gets.chomp > winalloc = case winunit >          when x == 1.50...2.50: ... >          when x == 2.50...3.80: ... >          when x == 3.80...5.50: ... >          else something You are not using Range#=== as Matz did. Please look carefully and read my previous reply. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/