Hi,
In message "[ruby-talk:15828] subclassing Date"
on 01/05/28, Michael Husmann <Michael.Husmann / teleatlas.com> writes:
|Using ruby 1.6.0 and trying to subclass the Date class like
|this:
|
|class My_date < Date
| def initialize(st)
| l = split(".")
| y, m, d = l.collect{|s| s.to_i}
| super(y,m,d)
| end
|end
|
|ruby throws the following error messages when invoking:
|d = My_date.new("2001.5.28")
|
|/usr/local/lib/ruby/1.6/date.rb:33:in `civil_to_jd':
|undefined method `-' for "2001.5.28":String (NameError)
|/usr/local/lib/ruby/1.6/date.rb:139:in `exist3?'
|/usr/local/lib/ruby/1.6/date.rb:147:in `new3'
You're calling `super("2001.5.28",...)'. I think there's something
wrong before calling super. Try:
class My_date < Date
def initialize(st)
l = st.split(".") # note "st."
y, m, d = l.collect{|s| s.to_i}
super(y,m,d)
end
end
matz.