Skip to content

Instantly share code, notes, and snippets.

@jasonneylon
Created April 7, 2011 10:07
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 jasonneylon/907478 to your computer and use it in GitHub Desktop.
Save jasonneylon/907478 to your computer and use it in GitHub Desktop.
Scottish ruby tutorial counter code
def counter(start=0, increment=1)
count = nil
lambda do
count.nil? ? count = start : count += increment
end
end
result = counter(2,3)
puts result.call
puts result.call
puts result.call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment