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,

Look at the answer here.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.