From: ahoward Date: 2003-05-09T06:14:35+09:00 Subject: state pattern in ruby rubyists- when implementing the state pattern/factory in ruby, i have used delegation before (require 'delegate') and this works well. however, it seem like something like this can work just as well - with faster execution times - for simple cases: module M class << self def new args if ... return A.new elsif ... return B.new else return C.new end end end private # parent class, perhaps abstract, interface, whatever... class M; end # delegate classes class A < M; end class B < M; end class C < M; end end allowing m = M.new args to return an A, B, or C - all supporting the methods of M::M via inheritence, interface, abstract inheritence using NotImpliemnted, polymorphism, etc. any thoughts on this? -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ara.t.howard@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================