diff options
| author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-19 09:42:44 +0000 |
|---|---|---|
| committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-19 09:42:44 +0000 |
| commit | 44169f487a3c864f172ce046068c920face9fb5e (patch) | |
| tree | 018527b7a45e6bd412237c4b227cbfee06b9648f /lib | |
| parent | 14e270843d00575c5deeb026fdbcd94146bf3a68 (diff) | |
| download | ruby-44169f487a3c864f172ce046068c920face9fb5e.tar.gz ruby-44169f487a3c864f172ce046068c920face9fb5e.tar.xz ruby-44169f487a3c864f172ce046068c920face9fb5e.zip | |
* lib/date.rb (once): use an instance variable which points a hash
as cache. [experimental]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/date.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/date.rb b/lib/date.rb index b20636481..63d6324ee 100644 --- a/lib/date.rb +++ b/lib/date.rb @@ -1101,13 +1101,13 @@ class Date class << self - def once(*ids) # :nodoc: + def once(*ids) # :nodoc: -- restricted for id in ids module_eval <<-"end;" alias_method :__#{id.to_i}__, :#{id.to_s} private :__#{id.to_i}__ - def #{id.to_s}(*args, &block) - (@__#{id.to_i}__ ||= [__#{id.to_i}__(*args, &block)])[0] + def #{id.to_s}(*args) + @__ca__[#{id.to_i}] ||= __#{id.to_i}__(*args) end end; end @@ -1136,7 +1136,10 @@ class Date # # Using one of the factory methods such as Date::civil is # generally easier and safer. - def initialize(ajd=0, of=0, sg=ITALY) @ajd, @of, @sg = ajd, of, sg end + def initialize(ajd=0, of=0, sg=ITALY) + @ajd, @of, @sg = ajd, of, sg + @__ca__ = {} + end # Get the date as an Astronomical Julian Day Number. def ajd() @ajd end |
