a.select!{|e| !e.nil?} NoMethodError: undefined method `select-6ren">
gpt4 book ai didi

ruby - ruby有数组方法select吗!或不?

转载 作者:数据小太阳 更新时间:2023-10-29 06:48:07 26 4
gpt4 key购买 nike

> a = %w(a b c)
=> ["a", "b", "c"]
> a.select!{|e| !e.nil?}
NoMethodError: undefined method `select!' for ["a", "b", "c"]:Array
from (irb):2

ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.5.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02

文档说有一个叫做select的方法!在数组中。

http://www.ruby-doc.org/core/classes/Array.html#M000252

最佳答案

Ruby 1.8.7 确实Array#reject!,但是:

>> a = [1, 2, nil]
=> [1, 2, nil]
>> a.reject! &:nil?
=> [1, 2]

关于ruby - ruby有数组方法select吗!或不?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5276306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com