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

前端 未结 4 603

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 03:05

    I'm hardly a Ruby expert, but as I recall, it means much the same as it would in C/C++, where it is the address-of operator. In other words, the method price itself is passed as an argument to sum, instead of price being called, and the result being passed to sum

提交回复
热议问题