码迷,mamicode.com
首页 > 其他好文 > 详细

Ruby的case语句

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

标签:正则表达式   表达   each   nil   ==   正则表达   when   正则   cas   

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语句

标签:正则表达式   表达   each   nil   ==   正则表达   when   正则   cas   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!