我试过了
Net::http.new(@site).head('/').kind_of? Net::httpOK
但我收到了这个:
error: in `kind_of?’: class or module required (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 endend解决方法 在您的代码中,您使用的是:
if Net::http.new(@site).head('/').kind_of? Net::httpOK == true
首先评估==,导致Net :: httpOK == true被评估为false.然后声明的其余部分变为:
if Net::http.new(@site).head('/').kind_of? false
导致你的TypeError.
在执行if语句时,不需要检查== true.如果if之后的语句求值为true,那么将评估if.无论如何,检查boolean == true是否被认为是错误的形式.
总结以上是内存溢出为你收集整理的ruby – 为什么这个命令在这个特定代码中不起作用?全部内容,希望文章能够帮你解决ruby – 为什么这个命令在这个特定代码中不起作用?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)