Ruby .reject! vs .delete_if [英] Ruby .reject! vs .delete_if
问题描述
谢谢!
编辑
我已阅读文档......我想我应该在我原来的问题中更加清楚。我想知道更多关于效率的差异。他们在如何删除商品方面的操作方式不同? (同样,忽略返回值,我明白这是一个区别,谢谢!) 解决方案
文档对此很清楚。
区别在于如果 reject!
不改变数组,它会返回 nil
。 delete_if
将返回未更改的数组。
Being new to Ruby, I have a question about the difference between the .reject! and .delete_if methods when dealing with hashes and arrays. If just wanting to get rid of certain objects, is there functionally any difference between the methods? And reason to use one over the other?
Thanks!
EDIT I have read the documentation...I guess I should have been more clear in my original question. I was wondering more about differences in efficiency. Do they operate differently in how they delete items? (Again, ignoring return value. I understand that is a difference. Thanks!)
The documentation is pretty clear about this.
The difference is that if reject!
does not change the array, it returns nil
. delete_if
will return the unchanged array.
这篇关于Ruby .reject! vs .delete_if的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!