Skip to content

Instantly share code, notes, and snippets.

@paulcc
Created April 7, 2011 10:01
Show Gist options
  • Save paulcc/907466 to your computer and use it in GitHub Desktop.
Save paulcc/907466 to your computer and use it in GitHub Desktop.
scottish ruby conf ex - counter
def counter(s = 0, i = 1)
c = s
lambda { o = c; c += i; o }
end
x = counter(10,2)
4.times { puts x.call }
y = counter(2,3)
6.times { puts y.call }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment