Ruby的case语句

后端开发   发布日期:2025年06月29日   浏览次数:92

Ruby的case语句

case语句使用的是===判断方式,可以进行更加广义的相等判断;

可以进行类型的判断,可以进行正则表达式的判断;

  1. array = ["a",1,nil]
  2. array.each { |ai|
  3. case ai
  4. when String
  5. puts "#{ai} is string"
  6. when Numeric
  7. puts "#{ai} is number"
  8. when nil
  9. puts "#{ai} is else"
  10. end
  11. }

 

以上就是Ruby的case语句的详细内容,更多关于Ruby的case语句的资料请关注九品源码其它相关文章!