* lib/date.rb (once): use an instance variable which points a hash
as cache. [experimental] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bf031c9699
commit
3449e0710c
@ -1,3 +1,8 @@
|
|||||||
|
Sat Jan 19 18:40:19 2008 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
* 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@dotrb.org>
|
Sat Jan 19 17:21:29 2008 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
* lib/date.rb, lib/date/format.rb: parse's hints as an
|
* lib/date.rb, lib/date/format.rb: parse's hints as an
|
||||||
|
11
lib/date.rb
11
lib/date.rb
@ -1101,13 +1101,13 @@ class Date
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def once(*ids) # :nodoc:
|
def once(*ids) # :nodoc: -- restricted
|
||||||
for id in ids
|
for id in ids
|
||||||
module_eval <<-"end;"
|
module_eval <<-"end;"
|
||||||
alias_method :__#{id.to_i}__, :#{id.to_s}
|
alias_method :__#{id.to_i}__, :#{id.to_s}
|
||||||
private :__#{id.to_i}__
|
private :__#{id.to_i}__
|
||||||
def #{id.to_s}(*args, &block)
|
def #{id.to_s}(*args)
|
||||||
(@__#{id.to_i}__ ||= [__#{id.to_i}__(*args, &block)])[0]
|
@__ca__[#{id.to_i}] ||= __#{id.to_i}__(*args)
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
@ -1136,7 +1136,10 @@ class Date
|
|||||||
#
|
#
|
||||||
# Using one of the factory methods such as Date::civil is
|
# Using one of the factory methods such as Date::civil is
|
||||||
# generally easier and safer.
|
# 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.
|
# Get the date as an Astronomical Julian Day Number.
|
||||||
def ajd() @ajd end
|
def ajd() @ajd end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user