【发布时间】:2019-11-06 08:54:08
【问题描述】:
我尝试使用相反的包含方法?在 ruby 中,即“string|array.exclude?”,这是我在交互式 ruby 上的代码。
this = "nice"
puts this.exclude? "n"
但是,它总是声明一个错误。
Traceback(最近一次通话最后一次):
4: from C:/Ruby26-x64/bin/irb.cmd:31:in `<main>' 3: from C:/Ruby26-x64/bin/irb.cmd:31:in `load' 2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>' 1: from (irb):14NoMethodError(未定义方法 `exclude?' for "nice":String)
我研究了很多,但没有找到解决方案。我想知道它是否只发生在我身上,这让我非常恼火。
谁能帮帮我。 非常感谢。
【问题讨论】:
-
!"string".include?(pattern) 不适合你?
标签: ruby