ruby-changes:3637
From: ko1@a...
Date: Sat, 19 Jan 2008 18:43:14 +0900 (JST)
Subject: [ruby-changes:3637] tadf - Ruby:r15126 (trunk): * lib/date.rb (once): use an instance variable which points a hash
tadf 2008-01-19 18:42:44 +0900 (Sat, 19 Jan 2008) New Revision: 15126 Modified files: trunk/ChangeLog trunk/lib/date.rb Log: * lib/date.rb (once): use an instance variable which points a hash as cache. [experimental] http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/date.rb?r1=15126&r2=15125&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15126&r2=15125&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 15125) +++ ChangeLog (revision 15126) @@ -1,3 +1,8 @@ +Sat Jan 19 18:40:19 2008 Tadayoshi Funaba <tadf@d...> + + * lib/date.rb (once): use an instance variable which points a hash + as cache. [experimental] + Sat Jan 19 17:21:29 2008 Tadayoshi Funaba <tadf@d...> * lib/date.rb, lib/date/format.rb: parse's hints as an Index: lib/date.rb =================================================================== --- lib/date.rb (revision 15125) +++ lib/date.rb (revision 15126) @@ -1101,13 +1101,13 @@ 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 @@ # # 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/