On Jan 13, 6:41=A0pm, Tim Roberts <t... / probo.com> wrote:
> flebber <flebber.c... / gmail.com> 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 =3D gets.chomp
> >winalloc =3D case winunit
> > =A0when x =3D=3D (1.50...2.50) then ...
> > =A0when x =3D=3D (2.50...3.80) then ...
> > =A0when x =3D=3D (3.80...5.50) then ...
> > =A0else something
> >end
>
> Perhaps its purpose would be clearer if you wrote it like Matz's code:
>
> x =3D gets.chomp
> winalloc =3D case x
> =A0 when (1.50...2.50) then ...
> =A0 when (2.50...3.80) then ...
> =A0 when (3.80...5.50) then ...
> =A0 else something
> end
> --
> Tim Roberts, t... / probo.com
> Providenza & Boekelheide, Inc.

I tough my code looked like Matz's

Matz's code
# Case expression tests ranges with =3D=3D=3D
generation =3D 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 =3D gets.chomp
winalloc =3D case winunit
          when x =3D=3D 1.50...2.50: ...
          when x =3D=3D 2.50...3.80: ...
          when x =3D=3D 3.80...5.50: ...
          else something