我想从 then 子句中访问 case 语句表达式,即
food = "cheese"
case food
when "dip" then "carrot sticks"
when "cheese" then "#{expr} crackers"
else
"mayo"
end
在这种情况下 expr 将是食物的当前价值。在这种情况下,我知道,我可以简单地访问变量 food,但在某些情况下,该值可能不再可访问(array.shift 等)。除了将 expr 移出到局部变量然后访问它之外,有没有办法直接访问 case expr 的值?
罗亚
ps 我知道这个具体的例子是微不足道的,它只是一个示例场景。