[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    [ruby-talk:29911] Re: How to check free diskspace?
From:       ptkwt () shell1 ! aracnet ! com (Phil Tomson)
Date:       2001-12-31 23:23:35
[Download RAW message or body]

In article <20011231165844.3910fe4d.daniel@zepeda-zone.net>,
Daniel P. Zepeda <daniel@zepeda-zone.net> wrote:
>On Tue, 1 Jan 2002 06:59:26 +0900
>Mathieu Bouchard <matju@sympatico.ca> wrote:
>
>> 
>> On Tue, 1 Jan 2002, Le Wang wrote:
>> > Hi all,
>> > I've checked "Programming Ruby", and searched the ML to no avail.  So
>> > how do you check free disk space, other than to parse 'df' output?
>> 
>> Mount = Struct.new(
>>   :device,
>>   :path,
>>   :fs_type,
>>   :options,
>>   :freq,
>>   :passno)
>> 
>> mounts = File.open("/etc/mtab") {|f|
>>   f.map {|x|
>>     Mount.new(*x.chomp.split) }}
>
>What does the '*' mean in this context? I've seen this idiom a couple of times
>on this list. I've tried the above code with and without the '*' and have noted
>that with the '*', each element from the split gets assigned to each part of the
>Struct, while an array gets assigned to just the first value of the
>Struct without
>the '*'. I understand what is doing, but *why* is it doing it? Is there
>somewhere
>this is documented (I must've missed it)? 

I'm sure it's in the Pickaxe book.
'*' in this context expands an array into it's seperate elements.  Since 
Mount's new takes six parameters, if the array has six elements then the 
'*' operator will cause each element to be matched to a parameter.

Phil

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic