From: Michael Husmann Date: 2001-05-28T18:10:06+09:00 Subject: [ruby-talk:15848] Re: subclassing Date --------------AA250E39030A1F17F9CC40D6 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Yukihiro Matsumoto wrote: > Hi, > > In message "[ruby-talk:15828] subclassing Date" > on 01/05/28, Michael Husmann 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. Hi Matz, yes I have forgotten the st before split. But the problem still exists after changing the code Michael -- Michael Husmann p.A. Tele Atlas Deutschland GmbH, Am neuen Horizont 1, 31177 Harsum PHONE: +(49) 5127 408-487, FAX: +(49) 5127 408-481 e-mail: Michael.Husmann@teleatlas.com --------------AA250E39030A1F17F9CC40D6 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Yukihiro Matsumoto wrote:
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.

Hi Matz,

yes I have forgotten the st before split. But the problem still exists after changing the code

Michael

--
Michael Husmann
p.A. Tele Atlas Deutschland GmbH, Am neuen Horizont 1, 31177 Harsum
PHONE: +(49) 5127 408-487, FAX: +(49) 5127 408-481
e-mail: Michael.Husmann@teleatlas.com
  --------------AA250E39030A1F17F9CC40D6--