Thanks I was about to ask too.

For the time being I made it this way:

  dayrange = DayRange.new [1,3,4,5,6,7], %w{Mo Di Mi Do Fr Sa So}
  p dayrange.to_s #=> "Mo, Mi-So"

I think that's the way it should work. If not, please tell me.

Morton Goldberg schrieb:
> Request for clarification.
> 
> Are you asking us to define a class or a top-level conversion method?
> 
> If it's a class you want, beside initialize, what methods are you asking
> for?
> 
> My guess is that you expect a 'to_s' that returns the human-readable
> form and a 'to_a' that returns an array of day numbers. Is this correct?
> Also, should 'initialize' accept mixed argument sequences? For example,
> which of following do you consider valid argument lists for 'initialize'?
> 
> ('Mon-Wednesday', 5)
> ('1-Wed', 5)
> ([1, 2, 3], 'Fri')
> (1, 2, 3, 'Fri')
> ('1-3', 'Fri')
> 
> Regards, Morton
> 
> On Aug 25, 2006, at 9:01 AM, Ruby Quiz wrote:
> 
>> by Bryan Donovan
>>
>> If you've ever created a web application that deals with scheduling
>> recurring
>> events, you may have found yourself creating a method to convert a
>> list of days
>> into a more human-readable string.
>>
>> For example, suppose a musician plays at a certain venue on Monday,
>> Tuesday,
>> Wednesday, and Saturday. You could pass a list of associated day
>> numbers to your
>> object or method, which might return "Mon-Wed, Sat".
>>
>> The purpose of this quiz is to find the best "Ruby way" to generate this
>> sentence-like string.
>>
>> Basically, the rules are:
>>
>>     * The class's constructor should accept a list of arguments that
>> can be day
>>       numbers (see day number hash below), day abbreviations ('Mon',
>> 'Tue', etc.),
>>       or the full names of the days ('Monday', 'Tuesday', etc.).
>>     * If an invalid day id is included in the argument list, the
>> constructor
>>       should raise an ArgumentError.
>>     * The days should be sorted starting with Monday.
>>     * Three or more consecutive days should be represented by listing
>> the first
>>       day followed by a hyphen (-), followed by the last day of the
>> range.
>>     * Individual days and the above day ranges should be separated by
>> commas.
>>     * The class should number days (accepting Integers or Strings) as
>> follows:
>>         1:  Mon
>>         2:  Tue
>>         3:  Wed
>>         4:  Thu
>>         5:  Fri
>>         6:  Sat
>>         7:  Sun
>>     * The class needs a method named #to_s that returns the day range
>> string.
>>       Here are some example lists of days and their expected returned
>> strings:
>>         1,2,3,4,5,6,7:  Mon-Sun
>>         1,2,3,6,7:      Mon-Wed, Sat, Sun
>>         1,3,4,5,6:      Mon, Wed-Sat
>>         2,3,4,6,7:      Tue-Thu, Sat, Sun
>>         1,3,4,6,7:      Mon, Wed, Thu, Sat, Sun
>>         7:              Sun
>>         1,7:            Mon, Sun
>>         1,8:            ArgumentError
>>
>> This is not intended to be a difficult quiz, but I think the solutions
>> would be
>> useful in many situations, especially in web applications. The
>> solution I have
>> come up with works and is relatively fast (fast enough for my purposes
>> anyway),
>> but isn't very elegant. I'm very interested in seeing how others
>> approach the
>> problem.
>>
> 
> 
>