[#1026] Is this a bug? — Dave Thomas <Dave@...>

18 messages 2000/01/03

[#1084] Infinite loop — Dave Thomas <Dave@...>

17 messages 2000/01/11

[#1104] The value of while... — Dave Thomas <Dave@...>

24 messages 2000/01/11

[ruby-talk:01201] Re: Question about 'open'

From: Dave Thomas <Dave@...>
Date: 2000-01-30 15:54:15 UTC
List: ruby-talk #1201
ts <decoux@moulon.inra.fr> writes:

> >>>>> "D" == Dave Thomas <Dave@thomases.com> writes:
> 
> D> D'accord! But I'm wondering why it is. The semantics of the open have
> D> it returning a result to both the parent and the child. It can't do
> D> that without executing the block, so shouldn't it be running the block 
> D> in both places?
> 
>  i.e. make a special case for - ?

Actually, I'd say that |<cmd> is the special case. The normal action
of 'open' is to return the File, either as a result or to the
block. If you use

   f = open("|-")
or
   f = open("|stuff")

the semantic is continued - it returns the File (or nil), both to the
child and to the parent.

So, continuing the theme

   open("|-") { |f| ... }

should be no different - it should give the block the File in the
parent and nil in the child.

But... I can see the argument the other way, that the block should
only be executed in the parent (the current behavior). In terms of
explaining what's going on, the current behavior is probably easier
too. It just surprised me when it happened.


Regards


Dave

In This Thread