Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/date/constructor.rb

Overview

Allow a Date to be constructed from any Date or DateTime subclass, or parsed from a String

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*a, &b) ⇒ Date

If someone calls allocate/initialize, make that work … just don’t mess up DateTime which is a subclass of Date



7
8
9
# File 'lib/date/constructor.rb', line 7

def initialize *a, &b
  marshal_load(self.class.new(*a, &b).marshal_dump) unless self.is_a?(DateTime)
end

Class Method Details

.new(*a, &b) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/date/constructor.rb', line 11

def self.new *a, &b
  if a[0].is_a?(String)
    parse(*a)
  elsif (a.size == 1)
    case a[0]
    when DateTime
	civil(a[0].year, a[0].month, a[0].day, a[0].start)
    when Date
	a[0].clone
    else
	civil(*a, &b)
    end
  else
    civil(*a, &b)
  end
end