Skip to content

Instantly share code, notes, and snippets.

@ohnishiakira
Created December 18, 2013 02:31
Show Gist options
  • Save ohnishiakira/8016420 to your computer and use it in GitHub Desktop.
Save ohnishiakira/8016420 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# coding: utf-8
require "date"
def default_time(now=DateTime.now)
@default_time ||= now
end
module ShowDefaultTime
def show_default_time(t=default_time)
t
end
end
class Test
extend ShowDefaultTime
def self.test
show_default_time
end
end
default_time DateTime.new 2013, 12, 9, 5, 0, 0
#
# 結果が同じになる想定だったが異なる
# (例は 2013/12/18 11:30:10 に実行した結果)
#
p default_time # => <DateTime: 2013-12-09T05:00:00+00:00 ((2456636j,18000s,0n),+0s,2299161j)>
p Test.test # => <DateTime: 2013-12-18T11:30:10+09:00 ((2456645j,9010s,735935000n),+32400s,2299161j)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment