|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
|
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 Farrel |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Farrel Lifson wrote:
> On 10/03/2008, Frantisek Psotka <frantisek.psotka@matfyz.cz> wrote: > > a = b if b > > a ||= b Nope. a ||= b is equivalent to a = a || b is equivalent to a = if a then a else b end is NOT equivalent to a = b if b HTH, Sebastian -- Jabber: sepp2k@jabber.org ICQ: 205544826 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Mon, Mar 10, 2008 at 11:50 AM, Farrel Lifson <farrel.lifson@gmail.com> wrote:
> > a ||= b > That's not right. It will give you a NameError, that b is undefined. a ||= b is equivalent to a = a || b which is the same as a = b if not a > > a = b if b > I know of no operator for it yet. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Mon, Mar 10, 2008 at 11:50 AM, Farrel Lifson <farrel.lifson@gmail.com> 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 > > Farrel a ||= b is a = a || b that is a = b if !a that is a = b unless a It is equal to "a = b if b" if both a and b are of boolean type (doesn't work for e.g. numbers). |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Mar 10, 11:50 am, Farrel Lifson <farrel.lif...@gmail.com> wrote:
> On 10/03/2008, Frantisek Psotka <frantisek.pso...@matfyz.cz> wrote: > > > is in ruby operator for: > > > a = b if b > > > a (operator) b > > a ||= b "a ||= b" means "a = b unless a". I don't think there is an operator for "a = b if b". Luckily, "a = b if b" is valid ruby code. "a = b || a" or "a = (b or a)" would also work. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
yes, i can write
a = b || a but isn't it more complex. imagine that b is nil. then a = a will be evaluated? maybe time for feature request? new operator a =|| (a = b if b) (variable = params[:nice_symbol] if params[:nice_symbol] doesnt look very nice) Lars wrote: > On Mar 10, 11:50 am, Farrel Lifson <farrel.lif...@gmail.com> wrote: >> On 10/03/2008, Frantisek Psotka <frantisek.pso...@matfyz.cz> wrote: >> >> > is in ruby operator for: >> >> > a = b if b >> >> > a (operator) b >> >> a ||= b > > "a ||= b" means "a = b unless a". > > I don't think there is an operator for "a = b if b". > > Luckily, "a = b if b" is valid ruby code. "a = b || a" or "a = (b or > a)" would also work. -- Posted via http://www.ruby-forum.com/. |
|
![]() |
| Outils de la discussion | |
|
|