Hi,

I cannot find a way of initialising all items in a class as per this bit of 
code.

#!/usr/bin/ruby

class File_list
        def initialize( row, name)
                @row = row
                @name = name
        end
        def name
                @name
        end
        def row
                @row
        end
        def ctime
                @ctime = File.stat(@name).mtime
        end
        def dur
                @dur = File.stat(@name).size/1700
        end
        def to_s
                "[EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL 
PROTECTED]"
        end
end

z="/var/spool/voice/incoming/*.rmd"
files = Dir[z].sort_by { |f| [File.new(f).mtime, f] }
puts "File list sorted by time"
puts files
puts

a1 = File_list.new(1, files[0])
puts "Details of a1"
puts a1.to_s
puts "   Duration in Seconds = "+ a1.dur.to_s
puts "     Modification Time = "+ a1.ctime.to_s

puts a1.to_s

======================= EOF ==============
When I first call a1.to_s it only prints the row and name. Not until I call 
a1.dur and a1.ctime individually will these two variables become initialised. 

Is there any way to initialise these variables when I call File_list.new ? 

Also is there a way to make this class into an array so as to hold a number of 
rows?


-- 
Regards,

Graham Smith
_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders

Reply via email to