From: rio4ruby Date: 2006-01-10T08:38:01+09:00 Subject: Re: Rio 0.3.7 Duane Johnson wrote: > > Copy a gzipped file un-gzipping it > > rio('afile.gz').gzip > rio('afile') > > > Why does 'gzip' unzip? How would one zip something up? Rio#gzip puts a Rio in gzip mode, so the referenced file will be read from and written to properly. We could rewrite the example: a_rio_referencing_a_gzipped_file = rio('afile.gz).gzip a_rio_referencing_a_file = rio('afile') a_rio_referencing_a_gzipped_file > a_rio_referencing_a_file > How would one zip something up? Turn the arrow around: rio('afile.gz').gzip < rio('afile') > Curious... why does +all+ take square brackets when +files+ uses > parens? Seems inconsistent upon first viewing. Both +files+ and +all+ are configuration methods. The usage: anarray = rio('adir').all['*.rb'] is syntactic sugar for anarray = rio('adir').all.entries('*.rb').to_a The abbreviated usage works because: 1. Rio#entries is the default selection method when iterating over directories. 2. The subscript operator passes its arguments to the most recently called selection method (in this case +entries+, even though it was never *explicitly* called) before it calls +to_a+. 3. Rio#all returns the Rio which called it. (All configuration methods do this, to support the readable shortened syntax) Since Rio#files is also a configuration method, it can be used similarly: rio('adir').files('*.rb') { |f| ... } # iterate over .rb files rio('adir').files['*.rb'] # returns an array of .rb files rio('adir').files('*.rb') > 'bdir' # copies .rb files to 'bdir' Hope this helps. -Christopher