ファイルプロパティ

あるディレクトリのファイルオブジェクトとして受け取る。

$: << 'lib'

require 'lib/rire'

class Foo < Rire::PropertyBase
  foreach do |f|
    has_property :name, f.to_s
    has_property :size, File.stat(f).size
    has_property :mtime, File.stat(f).mtime
  end
end

files = Foo.fetch(Dir::entries('.'))

puts "name, size, mtime"
files.each do |f|
  puts "#{f.name}, #{f.size}, #{f.mtime}"
end

出力結果

name, size, mtime
., 0, Thu May 01 22:17:17 +0900 2008
.., 0, Thu May 01 12:24:07 +0900 2008
lib, 0, Thu May 01 13:43:12 +0900 2008
v1.rb, 378, Thu May 01 22:17:17 +0900 2008