Ruby中的数组迭代

时间:2013-11-26 18:59:54

标签: ruby arrays

所以我动态创建了这个数组:

array = [ "Name can't be blank", "Email can't be blank",
      "Email is invalid", "Password can't be blank",
      "Password is too short (minimum is 6 characters)",
      "Password confirmation can't be blank" ]

我想要的是迭代这个数组,如果有值:

"Password can't be blank"

验证是否有值:

"Password confirmation can't be blank"

并摆脱它。

所以返回的数组将是:

    array = [ "Name can't be blank", "Email can't be blank",
      "Email is invalid", "Password can't be blank",
      "Password is too short (minimum is 6 characters)"]

非常感谢!

1 个答案:

答案 0 :(得分:0)

这就是你能够做到的。 include?检查"Password can't be blank"delete删除该项目。

if array.include? "Password can't be blank"
  array.delete "Password confirmation can't be blank"
end
相关问题