From: Brian Candler Date: 2003-02-22T06:19:08+09:00 Subject: Re: Extending existing classes under mod_ruby... (and the "ruby way") On Sat, Feb 22, 2003 at 03:23:01AM +0900, Frank Fejes wrote: > class String > def is_valid_date? > > end > end > > Now I can call: > > if entered_date.is_valid_date? > > But that does not work with mod_ruby and I feel funny about extending > such a fundamental class like String. ;) > > So, what's the ruby way of handling this? Thanks! Perhaps a class method. This particular operation is not tied to a particular object, but then if you wanted to do other operations on dates (e.g. calculate the number of days between two dates) you could then have instances representing a particular date. class MyDate def MyDate.is_valid?(str) # test if a string is valid ... end def initialize(str) # create a 'MyDate' object from string ... end end today = "2003-02-21" puts "hello" if MyDate.is_valid?(today) Incidentally, you might want to look at date.rb in the Ruby standard library, and date2 on RAA (I haven't used either) Regards, Brian.