"no implicit conversion of nil into String"在对象为 nil 时不应计算的代码中



这是代码:

if article.link && article.link.starts_with?(`https://www.youtube.com`) then article.link end

错误是指这部分:

article.link.starts_with?(`https://www.youtube.com`)

但是,如果 article.link 为零,则甚至不应该评估该部分。

如果问题出在article.link错误上

,则会NoMethodError: undefined method `starts_with?' for nil:NilClass

事实上,问题出在https://www.youtube.com表达式上。它的计算结果为nil。 你为什么要使用这些引号?将它们更改为""''

最新更新