如何在ruby中向next if语句添加消息

时间:2013-12-22 19:48:42

标签: ruby

如何将nextputs "#{web_url.status[0].to_i}组合在一起并在控制台中显示,但仅当if部分为真时才显示。

tried:
next if ... && puts "{web_url.status[0].to_i}"



  web_url  = open(url, :proxy => BaseParser::PROXY, "User-Agent" => BaseParser.rand_ua_string() )

  next if web_url.nil?
  next if web_url.status[0].to_i == 410
  next if web_url.status[0].to_i == 310
  next if web_url.status[0].to_i == 404
  next if web_url.status[0].to_i == 530

1 个答案:

答案 0 :(得分:4)

这是:

next puts "#{web_url.status[0].to_i}" if x == 2 # expression here

示例:

x = 1
until x > 3
  next puts("#{x} matched"),x+=1 if x == 2
  puts "this iteration has number #{x}"
  x += 1
end
# >> this iteration has number 1
# >> 2 matched
# >> this iteration has number 3

浏览文档keywords