Peter Bailey wrote:
> 
> Now, I have to admit, I really need to look at your code, Jay, because, 
> to me, it's like a different "dialect." 
> ...
> But, your 
> casual use of a black and opening a file here kind of blows me away, 
> actually.
> 

1) First attempt at writing the code:

f = File.new(file)
line1 = f.gets
f.close

if /%!PS-Adobe/ =~ line1
    File.rename(file, "#{file}.eps")

2)  Hmmm...I think I can make those first three lines shorter. If I use 
a File.open block that I read about in pickaxe, I won't have to call 
close():

line1 = nil
File.open {|file| line1 = f.gets}

if /%!PS-Adobe/ =~ line1
    File.rename(file, "#{file}.eps")

3) And, shorter still...:

line1 = File.open {|file| f.gets}

if /%!PS-Adobe/ =~ line1
    File.rename(file, "#{file}.eps")


4)  Hey, but look at 3). line1 appears on each line.  So I can take what 
line1 is equal to on the first line and substitute it's value in the 
second line:

if /%!PS-Adobe/ =~ File.open {|file| f.gets}
    File.rename(file, "#{file}.eps")
-- 
Posted via http://www.ruby-forum.com/.