ruby

作者: 迪爷 | 来源:发表于2017-06-23 17:09 被阅读0次

    Detect returns the first item in the list for which the block returns TRUE. Your first example:

    [1,2,3,4,5,6,7].detect { |x| x.between?(3,4) }
    => 3
    Returns 3 because that is the first item in the list that returns TRUE for the expression x.between?(3,4).

    detect stops iterating after the condition returns true for the first time. select will iterate until the end of the input list is reached and returns all of the items where the block returned true.

    相关文章

      网友评论

          本文标题:ruby

          本文链接:https://www.haomeiwen.com/subject/iaiccxtx.html