Take the First Step

Dwight Shih's Soap Box on the Internet Commons

Home Technology Sports Java
Mar 22 2005
technology

inject, inject, inject

If inject had a better name, then it would be easier for us rookies to remember that it’s the right way to accumulate values across an array:

1
irb(main):001:0> (1..10).inject(0) { |s,v| s += v }
=> 55

Might I suggest something along the line of:

  • accumulate
  • assemble
  • gather (my favorite)
  • ruby
Newer
Learn Ruby in Three Weeks
Older
Ruby Variable Scope and Blocks

Archives

  • 2017
  • 2016
  • 2015
  • 2014
  • 2013
  • 2012
  • 2011
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • 2004
  • 2003
© 2003–2017 Dwight Shih All Rights Reserved
Powered by Hexo
Home Technology Sports Java