[ create a new paste ] login | about

Link: http://codepad.org/jghT8uoG    [ raw code | output | fork ]

Ruby, pasted on Dec 1:
1
2
3
4
5
6
7
8
9
10
11
12
def cool
  @result ||= begin
    10_000_000.times { 1 + 1 } # spend lots of time
    5
  end
end

p Time.now
p cool # takes 4s
p Time.now
p cool # instant
p Time.now


Output:
1
2
3
4
5
Thu Dec 01 10:34:58 +0000 2011
5
Thu Dec 01 10:35:02 +0000 2011
5
Thu Dec 01 10:35:02 +0000 2011


Create a new paste based on this one


Comments: