Just to get you thinking in other directions (WARNING: THIS CODE WAS
TYPED OFF THE TOP OF MY HEAD AND HAS NOT BE DEBUGGED (OR EVEN RUN)):
class DaysOfWeek < string
Names = %w{ monday tuesday wednesday thursday friday saturday sunday }
Objects = Hash.new
Names.each { |day|
eval %Q{
def DaysOfWeek.#{day}
Objects["#{day}"] ||= DaysOfWeek.new("#{day}")
end
}
}
def DaysOfWeek.to_list
Objects.values
end
def DaysOfWeek.from_s(content)
Objects[content]
end
private
def initialize(str)
super(str)
end
end
Something along these lines would do pretty much what the original did.
-- MarkusQ