【问题标题】:Is there any opposite of include? method in Ruby? [duplicate]有没有包含的反义词? Ruby中的方法? [复制]
【发布时间】:2018-04-04 14:12:06
【问题描述】:

我有一个问题:我知道unless有没有与.include?相反的方法,但我想用if做,可以吗?我试过unless

unless variable.include?("something")
#..
end

我想用if 做,可以吗?我知道.!include?,但它不起作用(我不知道这个方法是否存在,但我在这个论坛上看到过)。

【问题讨论】:

  • 简短回答:在 vanilla ruby​​ 中没有,但 exclude? 存在于 ActiveSupport 中——主要由 Rails 应用程序使用。
  • !include? 实际上是 两个 方法:!include? 因此你必须写 !variable.include? 而不是 variable.!include?

标签: ruby-on-rails ruby


【解决方案1】:
if !variable.include?("something")

纯红宝石

if variable.exclude?("something")

在 Rails 中

【讨论】:

    猜你喜欢
    • 2012-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多