首页 > 其他 > 详细

Ruby的case语句

时间:2017-04-04 20:20:05      阅读:130      评论:0      收藏:0      [点我收藏+]

Ruby的case语句

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

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

array = ["a",1,nil]
array.each { |ai|
  case ai
    when String
      puts "#{ai} is string"
    when Numeric
      puts "#{ai} is number"
    when nil
      puts "#{ai} is else"


  end
}

 

Ruby的case语句

原文:http://www.cnblogs.com/stono/p/6666095.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!