0

Hi,

Is there any difference between inject(:+) and inject(&:+) ? If NO hen how these two kind of syntax with same method? And if Yes then why the output are same for both?

irb(main):005:0> [1, 2, 3].inject(&:+)
=> 6
irb(main):006:0> [1, 2, 3].inject(:+)
=> 6
irb(main):007:0>

Thanks,

3
Contributors
3
Replies
8
Views
4 Years
Discussion Span
Last Post by L7Sqr
0

That link is too heavy wieght, ltos of opinoin has been put over there. Any brief you want me to share,just the concept on the same!

Thanks

0

From the selected answer in Taywins link:

I didn't notice the ampersand. You don't need it, inject will work with a symbol. But if you do write it, the symbol is converted to block, it can be useful with other methods

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.