Understanding tap in Ruby

前端 未结 2 791

I am reviewing a piece of code from a Rails project and I came across the tap method. What does it do?

Also, it would be great if someone could help me

2条回答
  •  太阳男子
    2021-01-05 09:39

    Tap is a Ruby method from the Object class.

    This method yields x to the block and then returns x. This method is used to "tap into" a method chain, to perform operations on intermediate results within the chain.

提交回复
热议问题