What does the `&` mean in the following ruby syntax?

前端 未结 4 616

In the following ruby example, what does the & represent? Is it along the line of += in a loop?

payments.sum(&:price)
         


        
4条回答
  •  死守一世寂寞
    2020-12-04 02:57

    "If the last argument to a method is preceded by an ampersand, Ruby assumes that it is a Proc object. It removes it from the parameter list, converts the Proc object into a block, and associates it with the method."

    From Programming Ruby: The Pragmatic Programmers' Guide

    Read more about it in this article.

提交回复
热议问题