From: Ben Giddings Date: 2003-09-10T01:17:56+09:00 Subject: Re: ANN: MetaTags 1.0 Dave Thomas wrote: > We could still define the global method > > Date "date string" > > Which parsed the string, reporting errors for incorrect strings, and > then called the constructor with the three integers. > > This approach also allows for memoizing the returned values, which in > general you probably shouldn't do with raw constructors. Hmm... I think it might be a better idea to create a "memoizer factory" or something. Maybe instead of Date.new you'd say Date.build or Date.construct, and instead of passing it a string, you pass it a "memo string" or something to indicate it makes sense to memoize the operation. You could do this by simply having a 'date_memoizer.rb' file with contents like: class Date def self.construct(arg) @@memo_hash ||= Hash.new if arg.respond_to(:memoizable) ... else ... end end end The main problems I see are that: * Date() looks like a constructor for a Date object, if you're not familliar with Ruby's constructor syntax, and for anybody reading the code that could be a bad thing. It might seem like there are two kinds of constructors in Ruby, one for initializing from data, one for initializing from strings. * It's not obvious that Date() has any connection to memoization * I have an aversion to top-level functions. ;) Ben