archive.rb に対して、いろいろな方法を試しています。
Module の Mix-in って手もあるような気がして、以下のコードを書いていま
すが、うまくいきません。
include のところでコケてしまいます。
#!/usr/bin/ruby
include FileTest
class Archive
def what_type
raise "file #{@file} not found" unless exist?(@file)
@file[-3,3].downcase == 'lzh' and return Lha
@file[-3,3].downcase == 'tgz' and return Tar
@file[-6,6].downcase == 'tar.gz' and return Tar
`file #{@file}` =~ /lha.+archive/i and return Lha
raise "file #{@file} is not an archive file."
end
def initialize (file)
@file=file
@type=what_type
include @type
end
def print_id
puts "#{name}"
puts "This file is '#{@file}'."
end
def delete_extracted_files
@extracted_files.each { |f| File.unlink(f) if exist?(f) }
end
end
module Lha
def list (file)
`lha l #{file}`.split (/\n/)[2..-3].filter { |l| l[46..-1]}
end
def extract (file)
@extracted_files=`lha xf #{file}`.split (/\n/).filter { |l| l.split[0] }
end
end
module Tar
def list (file)
`tar tzf #{file}`.split (/\n/)
end
def extract (file)
@extracted_files=`tar xzvf #{file}`.split (/\n/)
end
end
---
そして irb -r archive.rb
irb(main):001:0> a=Archive.new ("/dos/comwin/filer091.lzh")
NameError: undefined method `include' for #<Archive:0x402222c0>
./archive.rb:24:in `initialize'
(irb):1:in `new'
(irb):1
(irb_local_binding):1:in `eval'
--
Takashi Nishimoto: g96p0935 / mse.waseda.ac.jp
I love Emacs, zsh, and Linux!!
See ftp://ftp.misao.gr.jp/pub/tak/README
Key fingerprint = EE D7 1D 18 A9 42 C0 8A 63 E7 F2 AC 4D C7 83 6B