ruby - 如何在ruby中的下一个if语句中添加一条消息

标签 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

最佳答案

在这里:

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 .

关于ruby - 如何在ruby中的下一个if语句中添加一条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20733364/

相关文章:

mysql - 如何实现可移植的 MySQL 并在 Linux 下以非 root 身份从 Ruby 连接到它

ruby-on-rails - Rails 中用于多个请求的实例变量

ruby - Puppet 模板迭代和 yaml 文件

ruby - 无法加载此类文件 -- smarter_csv (LoadError)

ruby - 有没有更有效的方法将数组转换为散列?

ruby - 检测 eventmachine 断开连接并测试重新连接

ruby - 将数组转换为哈希,同时删除重复键和添加值

ruby - 如何获取 Ruby SSLContext 对象的 ssl_version

javascript - 如何在 Rails 中正确传递 JSON

ruby - 当 Controller 中的行被分成多行时,开发中的 Rails 3 语法错误