[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:02041] Re: class File acting funny!

From: matz@... (Yukihiro Matsumoto)
Date: 2000-03-21 01:24:20 UTC
List: ruby-talk #2041
Hi,

In message "[ruby-talk:02034] class File acting funny!"
    on 00/03/20, "David Douthitt" <DDouthitt@cuna.com> 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<DelegateClass(IO)
            attr_accessor :locked, :lockdir, :lockfile
            ...
         end

							matz.

In This Thread