Created
September 10, 2011 02:24
-
-
Save JEG2/1207848 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def closure_with_state(start, multiplier) | |
i = -1 | |
current = nil | |
lambda { current = start * (multiplier * (i += 1)) } | |
end | |
doubles = closure_with_state(1, 2) | |
triples = closure_with_state(1, 3) | |
p Array.new(10) { doubles.call } | |
p Array.new(10) { triples.call } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment