Discussion: newbie question
Afficher un message
Vieux 10/03/2008, 13h08   #6
Alex Young
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie question

On Mon, 2008-03-10 at 19:50 +0900, Farrel Lifson wrote:
> On 10/03/2008, Frantisek Psotka <frantisek.psotka@matfyz.cz> wrote:
> > is in ruby operator for:
> >
> > a = b if b
> >
> > a (operator) b

>
> a ||= b


Not quite:

irb(main):007:0> a = 1
=> 1
irb(main):008:0> b = 2
=> 2
irb(main):009:0> a ||= b
=> 1
irb(main):010:0>
irb(main):011:0* a
=> 1
irb(main):012:0> a = b if b
=> 2
irb(main):013:0> a
=> 2

a ||= b is equivalent to a = b if !a, which isn't quite the same thing
as a = b if b.

--
Alex


  Réponse avec citation
 
Page generated in 0,05199 seconds with 9 queries