无论如何我可以在 ruby​​ 案例中使用 if else ..end

use*_*406 2 ruby switch-statement

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
Run Code Online (Sandbox Code Playgroud)

有没有办法在case语句中包含上面的if?

ste*_*lag 5

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
Run Code Online (Sandbox Code Playgroud)