Will system be called both times all the time, or will the first one
be called only when the unless condition is satisfied, or will both
calls only be enacted when the unless condition is satisfied? I've
seen examples that used else statements with unless calls, but I'm not
sure if this is needed here or not. Unless is new to me
Will system be called both times all the time, or will the first one
be called only when the unless condition is satisfied, or will both
calls only be enacted when the unless condition is satisfied? I've
seen examples that used else statements with unless calls, but I'm not
sure if this is needed here or not. Unless is new to me
both system calls will be always invoked. The statement under "unless" scope is ftp.get(str), which will be always invoked unless str.index('d') == 0
you can use unless in two ways (shown below). The first one is a one-liner and it goes immediately after the conditioned statement. The second one marks the beginning of the conditioned block. The first one should ring a bell with perl developers and the second with C/Java/Javascript ones
whatever unless condition
unless condition
whatever
and_so_on
end
regards,
javier
Lincoln Anderson wrote:
···
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Using this snippet:
Will system be called both times all the time, or will the first one
be called only when the unless condition is satisfied, or will both
calls only be enacted when the unless condition is satisfied? I've
seen examples that used else statements with unless calls, but I'm not
sure if this is needed here or not. Unless is new to me
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFCKITKte2c0P8BH0RAtHAAJkBVZQ5yV8glhpACggeDPcH2RtCxgCeJRPv
PCFuN23jhfTfvcv4NP3rDBY=
=X7eL
-----END PGP SIGNATURE-----
Will system be called both times all the time, or will the first one
be called only when the unless condition is satisfied, or will both
calls only be enacted when the unless condition is satisfied? I've
seen examples that used else statements with unless calls, but I'm not
sure if this is needed here or not. Unless is new to me
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
Not the OP, but thank you! Somehow "if not" resonates better in my head than
"unless". I wonder if many other people, not yet intimate with unless in
Ruby, find it the same.
Probably too late to change, and I'm not advocating a change, but if I were
writing a new programming language ...
(I.e., ifnot, somewhat analogous to the elseif construct in some languages).
Randy Kramer
···
On Thursday 14 September 2006 01:14 am, Mike Dvorkin wrote:
In your example "unless" is applicable only to the line it appears
in. Synonym of "unless" is "if not", i.e.:
both system calls will be always invoked. The statement under
"unless" scope is ftp.get(str), which will be always invoked unless
str.index('d') == 0
you can use unless in two ways (shown below). The first one is a
one-liner and it goes immediately after the conditioned statement.
The second one marks the beginning of the conditioned block. The
first one should ring a bell with perl developers and the second
with C/Java/Javascript ones
whatever unless condition
unless condition whatever and_so_on end
regards,
javier
Thank you for this clarification. I kinda figured this was the case,
but was not sure. Your assistance is greatly appreciated.
Not the OP, but thank you! Somehow "if not" resonates better in my head
than
"unless". I wonder if many other people, not yet intimate with unless
in
Ruby, find it the same.
Yeah, I usually have to rephrase it in my head still to make 'unless'
flow. I'm still very very new to Ruby though. If I used Ruby more, I'm
sure it would come quicker.
In your example "unless" is applicable only to the line it
appears in. Synonym of "unless" is "if not", i.e.:
Not the OP, but thank you! Somehow "if not" resonates better in my
head than "unless". I wonder if many other people, not yet
intimate with unless in Ruby, find it the same.
Probably too late to change, and I'm not advocating a change, but
if I were writing a new programming language ...
(I.e., ifnot, somewhat analogous to the elseif construct in some
languages).
Randy Kramer
VB has an IsNot operator: If IsNot(a) Then
But I actually like the unless instruction, as it sets an action that
you want to process except in a certain case. The code snippet I
posted is part of a series of FTP functions I'm writing for an
ftpmirror style script. In that case, I want the client to FTP#get
items from a directory listing (obtained through a recursive listing
funtion adapted from a snippet provided by Vincent Arnoux) unless the
item is itself a directory. In that case, I want it mkdir on the
client side a directory of the same name and structure as the one it
encounters.
I assume this works better? Or in order to use else do I need to
switch to a multiline unless statement:
unless str.index('d')==0
ftp.get(str)
else
...
end
Your continued insight is much appreciated.
Lincoln Anderson
···
On Thursday 14 September 2006 01:14 am, Mike Dvorkin wrote:
On Thu, Sep 14, 2006 at 10:40:16PM +0900, Randy Kramer wrote:
On Thursday 14 September 2006 01:14 am, Mike Dvorkin wrote:
> In your example "unless" is applicable only to the line it appears
> in. Synonym of "unless" is "if not", i.e.:
Not the OP, but thank you! Somehow "if not" resonates better in my head than
"unless". I wonder if many other people, not yet intimate with unless in
Ruby, find it the same.
Probably too late to change, and I'm not advocating a change, but if I were
writing a new programming language ...
(I.e., ifnot, somewhat analogous to the elseif construct in some languages).
For me, it took some years before I started using unless and feel
comfortable with it. However, after I've trained myself to actually
use it, it flows very naturally - more naturally than if not or
"ifnot", as both tokenize in my brain to two tokens, of which one is a
negation - and that's much more work to process than the single case
"unless".
Eivind.
···
On 9/14/06, Randy Kramer <rhkramer@gmail.com> wrote:
Not the OP, but thank you! Somehow "if not" resonates better in my head than
"unless". I wonder if many other people, not yet intimate with unless in
Ruby, find it the same.
Probably too late to change, and I'm not advocating a change, but if I were
writing a new programming language ...
(I.e., ifnot, somewhat analogous to the elseif construct in some languages).
On 9/14/06, William Crawford <wccrawford@gmail.com> wrote:
Randy Kramer wrote:
> Not the OP, but thank you! Somehow "if not" resonates better in my head
> than
> "unless". I wonder if many other people, not yet intimate with unless
> in
> Ruby, find it the same.
Yeah, I usually have to rephrase it in my head still to make 'unless'
flow. I'm still very very new to Ruby though. If I used Ruby more, I'm
sure it would come quicker.
dir.each {|str|
ftp.get(str) unless str.index('d') == 0
else
str = str.split('/')
# ...
end
}
end
You'll get an unexpected kELSE error on line 3. The unless statement is
still applyins only to line 2 here, it acts as the negative form of if
BUT as a oneliner. To actually create a block-like behavior, you must
write something like:
I debated about whether to reply to this--there's probably really no need for
a reply, but just to acknowledge that I am listening:
Yes, you are clearly right (in cases where I'm writing code) --I guess I was
more concerned about understanding it when finding it in someone else's
code.
Randy Kramer
···
On Friday 15 September 2006 09:46 am, Logan Capaldo wrote:
On Thu, Sep 14, 2006 at 10:40:16PM +0900, Randy Kramer wrote:
> On Thursday 14 September 2006 01:14 am, Mike Dvorkin wrote:
> > In your example "unless" is applicable only to the line it appears
> > in. Synonym of "unless" is "if not", i.e.:
>
> Not the OP, but thank you! Somehow "if not" resonates better in my head
> than "unless". I wonder if many other people, not yet intimate with
> unless in Ruby, find it the same.
>
> Probably too late to change, and I'm not advocating a change, but if I
> were writing a new programming language ...
>
> (I.e., ifnot, somewhat analogous to the elseif construct in some
> languages).