Skip to content

Instantly share code, notes, and snippets.

@bsa7
Created June 10, 2014 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsa7/cbc9d2fc883fcbd2ad32 to your computer and use it in GitHub Desktop.
Save bsa7/cbc9d2fc883fcbd2ad32 to your computer and use it in GitHub Desktop.
Ruby inject
n=10
(1..n).inject(:*) || 1
## 1 ######### 2 #### 3
#1. this is a enum object
#2. Do an operation (*) with accumulated result and next element - 1..3: res = 1 * 2 * 3
#3. this is a foolprof - if an enum object is nil, result alway be the 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment