Tuesday, October 8, 2019

Sharing a great example of ruby's & operator:

By prepending & to a symbol you are creating a lambda function that will call method with a name of that symbol on the object you pass into this function. Taking that into account:
ar.map(&:reverse)
is roughly equivalent to:
ar.map { |element| element.reverse }

No comments:

Post a Comment