Joined May 2011
·
Avatar white

Luca Guidi

Senior Developer at Litmus
Senior Developer
Litmus
·
Rome, Italy
·
·
·

Posted to Constants in CoffeeScript over 1 year ago

Thanks for the clarification. Was this syntax introduced recently? IIRC, my first attempt was written like your last example, but it didn't worked.

Correct syntax highlight for this protip:
https://gist.github.com/jodosha/7410007

It looks like the Ruby syntax here is broken.

Posted to Ruby implicit coercion over 1 year ago

@apecox In this case, if you omit 0, you're forced to implement #+ in InvoiceValue::Entry. This because the loop don't have an initial value and tries to call #+ on all the entries.

Instead, with that explicit argument the VM tries to do 0.+(entry), that means a Fixnum with an InvoiceValue::Entry so asks to the last one to coerce itself, and the trick works.

So, there is a win in having that 0.

Achievements
1,313 Karma
78,899 Total ProTip Views