Skip to content

Instantly share code, notes, and snippets.

@webcoderph
Created April 3, 2018 05:57
Show Gist options
  • Save webcoderph/b906238d1a2cd687c52b548410ed8a2a to your computer and use it in GitHub Desktop.
Save webcoderph/b906238d1a2cd687c52b548410ed8a2a to your computer and use it in GitHub Desktop.
Ruby Memoization
def test(input)
@input ||= input
puts "TEST #{@input}"
end
alice = "im alice"
veronica = "im veronica"
thr = []
thr << Thread.new { test(alice) }
thr << Thread.new { test(veronica) }
thr.each { |t| t.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment