Skip to content

Commit

Permalink
distribute #once for each method for clarity in Date
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Sep 20, 2013
1 parent 10a456e commit 1a88876
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/ruby/1.9/date.rb
Expand Up @@ -1102,16 +1102,14 @@ def self.jisx0301(str='-4712-01-01', sg=ITALY) # :nodoc:

class << self

def once(*ids) # :nodoc: -- restricted
for id in ids
module_eval <<-"end;"
alias_method :__#{id.object_id}__, :#{id.to_s}
private :__#{id.object_id}__
def #{id.to_s}(*args)
@__ca__[#{id.object_id}] ||= __#{id.object_id}__(*args)
end
end;
end
def once(id) # :nodoc: -- restricted
module_eval <<-"end;"
alias_method :__#{id.object_id}__, :#{id.to_s}
private :__#{id.object_id}__
def #{id.to_s}(*args)
@__ca__[#{id.object_id}] ||= __#{id.object_id}__(*args)
end
end;
end # <<dummy
private :once

Expand Down Expand Up @@ -1169,17 +1167,20 @@ def amjd() ajd_to_amjd(ajd) end

# Get the date as a Julian Day Number.
def jd() ajd_to_jd(ajd, @of)[0] end
once :jd

# Get any fractional day part of the date.
def day_fraction() ajd_to_jd(ajd, @of)[1] end
once :day_fraction

# Get the date as a Modified Julian Day Number.
def mjd() jd_to_mjd(jd) end
once :mjd

# Get the date as the number of days since the Day of Calendar
# Reform (in Italy and the Catholic countries).
def ld() jd_to_ld(jd) end
once :jd, :day_fraction, :mjd, :ld
once :ld

def joda_year_to_date_year(year)
if year < 0 and julian?
Expand Down

0 comments on commit 1a88876

Please sign in to comment.