Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway I can use if else inside ruby case..end

case search_term
when 'a'
  ptr = 0
when 'b'
  ptr = 1
when 'c' 
  ptr = 2
else
  ptr = 99
end

if location = 'xyz' and search_term = 'c'
ptr = 0
end

Is there any way to include the if above in the case statement?

like image 508
user2825406 Avatar asked Sep 02 '25 09:09

user2825406


1 Answers

ptr = case search_term
when 'a'
   0
when 'b'
   1
when 'c' 
  if location == 'xyz' then  #note the ==
    0 
  else 
    2
  end 
else
  99
end
like image 172
steenslag Avatar answered Sep 04 '25 22:09

steenslag