From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-01-01T08:23:35+09:00 Subject: [ruby-talk:29911] Re: How to check free diskspace? In article <20011231165844.3910fe4d.daniel@zepeda-zone.net>, Daniel P. Zepeda wrote: >On Tue, 1 Jan 2002 06:59:26 +0900 >Mathieu Bouchard 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