[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02794] Re: Time Conversions

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-05-12 17:20:08 UTC
List: ruby-talk #2794
Sorry if this is in some ugly html or something, this just looks like I'm
using "I LOVE YOU"-mailing system again...
 
Dave:
>>t = Time.local(*parsedate("Fri May 12 2000 10:48a")[0,6])
>>p t  # => Fri May 12 10:48:00 CDT 2000
David Douthitt:
>What does the * in *parsedate do?
 
parsedate returns array full of parsed date&time attributes. The first five
are year, month, day, hour and min (probably the next is seconds and the
seventh millisecs). This is clear from Matz-version of the code:
 
  year, month, day, hour, min = ParseDate.parsedate("Fri May 12 2000
10:48a")

The Dave-version star ('*') indicates that the array should be flattened
before call to Time.local. So we would call
 
  Time.local(2000, 5, 12, 10, 48, 0)     # passes 6 arguments
 
instead of
 
  Time.local( [ 2000, 5, 12, 10, 48, 0] )   # passes one argument, one array
 
I'm not sure what's your second question but
 
> You use the array subscript [0,6] (which I read as 
> the zeroth element and the sixth element....)  
 
Means is subscripting elements [0,1,2,3,4,5].
 
> Matz uses [0..4] (which I read as the zeroth element 
> THROUGH the fourth element.)  
 
Is subscripting [0,1,2,3,4]. Version with three dots [0...4] would have been
[0,1,2,3].
 
    - Aleksi

In This Thread

Prev Next