J
Jonathan
Is there a cool way to do this without calling the function twice?:
a = func(b) unless func(b).nil? (AKA)
a = func(b) if func(b)
a = func(b) unless func(b).nil? (AKA)
a = func(b) if func(b)
a = x unless (x = func(b)).nil?Jonathan said:Is there a cool way to do this without calling the function twice?:
a = func(b) unless func(b).nil? (AKA)
a = x if (x = func(b)).a = func(b) if func(b)
Jonathan said:Is there a cool way to do this without calling the function twice?:
a = func(b) unless func(b).nil? (AKA)
a = func(b) if func(b)
Jonathan said:Is there a cool way to do this without calling the function twice?:
a = func(b) unless func(b).nil? (AKA)
a = func(b) if func(b)
and if a did not exist before?a = func(b) || a
Is there a cool way to do this without calling the function twice?:
a = func(b) unless func(b).nil? (AKA)
a = func(b) if func(b)
and if a did not exist before?
Is there a cool way to do this without calling the function twice?:
a = func(b) unless func(b).nil? (AKA)
a = func(b) if func(b)
Thx Nobu, that is as a matter of fact a "logical" and "functional"Hi,
At Fri, 13 Apr 2007 17:57:47 +0900,
Robert Dober wrote in [ruby-talk:247783]:and if a did not exist before?
a does exist at the assignment and initialized as nil.
x = func bJust to throw something obvious (which has not been mentioned so far)
into the mix:
x = func(b)
a = x if x
robert
Is there a cool way to do this without calling the function twice?:
a = func(b) unless func(b).nil? (AKA)
a = func(b) if func(b)
x = func b
a ||=x
How many combinations might we come up with ?
On 13.04.2007 13:07, Robert Dober wrote:
Sure no argument here.Certainly a lot more. However, my main point was to simply store the
result of func(b) in another variable and reuse that. Sometimes the
cool solutions are not without issues (see the other postings) and a
pragmatic solution can be better at times.
Sure no argument here.
I just screwed up, I am touched that you have not even seen my *serious
blunder*
a = x if x
is kind of *not*
a ||=x
Sorry Folks
Sure no argument here.
I just screwed up, I am touched that you have not even seen my
*serious blunder*
a = x if x
is kind of *not*
a ||=x
Really nice of you to say so, but to be honest, 99.99999% of theI suspect we've all made that mistake at one time or another
Really nice of you to say so, but to be honest, 99.99999% of the
people having made that mistake wisely refused to send it to the ML
irb(main):001:0> a=3D1
Robert Dober said:Thx Nobu, that is as a matter of fact a "logical" and "functional"Hi,
At Fri, 13 Apr 2007 17:57:47 +0900,
Robert Dober wrote in [ruby-talk:247783]:
a = func(b) || a
and if a did not exist before?
a does exist at the assignment and initialized as nil.
explanation, but my question was rather conceptional.
Do make it clear I will be a little bit blunt, forgive me.
I do not like that behavior!
And you ?
It's very philosophical:
$ ruby -e 'thing = thing; p thing'
nil
No I am too young to die, because that means we need python call syntaxSo you are proposing all undefined locals return nil too? }}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.