Ruby - case when statement

Introduction

Consider the following code:

Demo

fruit = "orange" 
case fruit # w w  w .  j av a  2 s.  c om
 when "orange" 
 color = "orange" 
 when "apple" 
 color = "green" 
 when "banana" 
 color = "yellow" 
 else 
 color = "unknown" 
end

Related Topics