1.11M Members

Is there any difference between `inject(:+) and inject(&:+)` ?

 
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,

 
0
 

Look at the answer here.

 
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

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article