相关疑难解决方法(0)

ruby Enumerable#first vs #take

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

4
推荐指数
1
解决办法
510
查看次数

标签 统计

ruby ×1