Advertisement
Hiteshw11

Use of Case Statement in Ruby

Sep 26th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.63 KB | None | 0 0
  1. def monthname(month)
  2.  case month
  3.   when "jan"
  4.     full_month="January"
  5.   when "feb"
  6.     full_month="February"
  7.   when "mar"
  8.     full_month="March"
  9.   when "apr"
  10.     full_month="April"
  11.   when "may"
  12.     full_month="May"
  13.   when "jun"
  14.     full_month="June"
  15.   when "jul"
  16.     full_month="July"
  17.   when "aug"
  18.     full_month="August"
  19.   when "sep"
  20.     full_month="September"
  21.   when "oct"
  22.     full_month="October"
  23.   when "nov"
  24.     full_month="November"
  25.   when "dec"
  26.     full_month="December"
  27.   else
  28.     puts "Invalid abbreviation"
  29.   end
  30.  return full_month
  31. end
  32.  
  33. puts "Enter the month abbreviation"
  34. a=gets.chomp()
  35. puts monthname(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement