ruby Enumerable/Array first(n)
和take(n)
?之间有什么区别?
我模糊地回忆take
起与懒惰评估有关,但我无法弄清楚如何使用它来做到这一点,并且找不到任何有用的谷歌搜索或在文档中."take"是google的硬方法名称.
first(n)
和take(n)
被记录的漂亮相同,没有太大的帮助.
first ? obj or nil
first(n) ? an_array
Returns the first element, or the first n elements, of the enumerable. If the enumerable is empty, the first form returns nil, and the second form returns an empty array.
Run Code Online (Sandbox Code Playgroud)
-
take(n) ? array
Returns first n elements from enum.
Run Code Online (Sandbox Code Playgroud)
告诉我"与懒惰的评价有关"是不够的,我有点记得已经,我需要一个如何使用它的例子,相比之下first
.
ruby ×1