From: timr Date: 2010-11-13T04:20:16+09:00 Subject: Re: Scheme's (cond ((assertion) (value))...(else (value))) statement implemented in ruby? On Nov 11, 8:43 pm, John W Higgins wrote: > [Note:  parts of this message were removed to make it a legal post.] > > Good Morning, > > On Thu, Nov 11, 2010 at 8:25 PM, timr wrote: > > On Nov 11, 5:51 pm, Clifford Heath wrote: > > > Case interrogates a single variable for its state--whether it falls in > > a certain range, or is equal to such and such a value. The cond > > statement is much more flexible, in that each assertion can be > > completely unrelated to the other assertions--i.e. they can cover more > > than the state of a single variable. > > Nope, well sort of nope - you are right that it checks against a single > variable but you are missing the trick. However the default "variable" for > case is true and there are lots of options outside of the default as well. > > As an example > > x = 1 > y = 2 > case >   when x == 2 then puts 'x' >   when y == 2 then puts 'y' > end > > That outputs a nice shiny "y" > > or > > x = 1 > y = 2 > case false >   when x == 2 then puts 'x' >   when y == 2 then puts 'y' > end > > This outputs an even shiner "x" > > And even nicer > > x = 1 > y = 2 > case 2 >   when x then puts 'x' >   when y then puts 'y' > end > > A nice shiny 'y' pops up on the screen > > John Oh, I see. I have always seen it in the simplest form only: print "Enter your grade: " grade = gets.chomp case grade when "A" puts 'Well done!' when "B" puts 'Try harder!' when "C" puts 'You need help!!!' else puts "You just making it up!" end Thanks. That is certainly better. Tim