From: James Edward Gray II Date: 2007-05-10T21:33:19+09:00 Subject: Re: The Factory Method On May 10, 2007, at 1:56 AM, Enrique Comba Riepenhausen wrote: > I was thinking about the Factory Method Pattern and following came > to my mind. In addition to Pat's great answer, I think it's important to note that classes are objects in Ruby. This often aids in Factory pattern scenarios. For example: >> class Prose >> def initialize(title, author) >> @title = title >> @author = author >> end >> def inspect >> "#{self.class}: #{@title} by #{@author}" >> end >> end => nil >> class Novel < Prose; end => nil >> class ShortStory < Prose; end => nil >> class Author >> def initialize(name) >> @name = name >> end >> def to_s >> @name >> end >> def write(type, title) >> type.new(title, self) >> end >> end => nil >> james = Author.new("James") => # >> james.write(Novel, "Ruby: The Girl I Loved") => Novel: Ruby: The Girl I Loved by James >> james.write(ShortStory, "Little Ruby Riding Hood") => ShortStory: Little Ruby Riding Hood by James Just some more food for thought. James Edward Gray II