From: matz@... (Yukihiro Matsumoto) Date: 2000-03-21T10:24:20+09:00 Subject: [ruby-talk:02041] Re: class File acting funny! Hi, In message "[ruby-talk:02034] class File acting funny!" on 00/03/20, "David Douthitt" writes: |Designing my own iterators isn't a problem, but this lock class seems |to be. I get many funny errors: | * Lock.new insisted on 1 parameter - but initialize method had NO parameters First of all, IO and its subclasses does not call `initialize' yet. Second of all, `initialize' was called in the Class.new, thus the number of argument to `new' and `initialize' must be exactly same, unless explicit arguments given to `super'. | def Lock.new |# raise "Lockdir not set!" if @lockdir == nil; | raise "\$0 not set?!" if $0 == nil; | | super ("/var/spool/locks" + "/" + File.basename($0) + ".lock", "w") | end | * $0 was not being recognized in parameter default value expressions It works on my machine: def a(p=$0) p p end | * print "foo" would generate: in 'write': not open for writing (IOError) I'm not sure but a output IO was screwed up somehow I think. | * $stdio evaluates to nil There's no $stdio predefined, but $stdin, $stdout, $stderr. | * flock appears to fail on non-existant files (?) and says in the | documentation "advisory" lock.... See `man 2 flock' if you're using UNIX box. Advisory lock requires a file to be exist. Two work arounds: (a) Wait until IO calls `initialize', somewhere in this month I think. (b) Use delegator, e.g. require 'delegate class Lock