我怎么会这样呢?我试过了
Net::HTTP.new(@site).head('/').kind_of? Net::HTTPOK
Run Code Online (Sandbox Code Playgroud)
但我收到了这个:
错误:在`kind_of?'中:需要的类或模块(TypeError)
我觉得我的代码有问题,你能看一下吗?我知道它非常混乱和非常糟糕,我是一名编程学生,我正在学习.如果您有任何改进的想法,请告诉我!
此外,还有一些东西搞砸了包含在其中的目标.出于某种原因,当我尝试结束所有defs时,我得到意外的结束错误.
这是我在上下文中的代码:
def begindownload
require 'net/http'
puts "Enter the URL of the site that you want to rip images from (use www.*website*.com/folder/file.html or other extension format):"
while @site = gets.chomp
puts "Querying " + @site
if Net::HTTP.new(@site).head('/').kind_of? Net::HTTPOK == true
puts "Site is online!"
else
puts "Site is offline. Try again."
end
end
end
Run Code Online (Sandbox Code Playgroud)
在您的代码中,您使用的是:
if Net::HTTP.new(@site).head('/').kind_of? Net::HTTPOK == true
Run Code Online (Sandbox Code Playgroud)
所述==被首先计算使Net::HTTPOK == true要评估到false.然后声明的其余部分变为:
if Net::HTTP.new(@site).head('/').kind_of? false
Run Code Online (Sandbox Code Playgroud)
导致你的TypeError.
您不需要检查== true何时进行if声明.如果会后声明if的计算结果为true,则if进行评估.== true无论如何,检查布尔值是否被视为坏形式.
| 归档时间: |
|
| 查看次数: |
884 次 |
| 最近记录: |