Is there any super cool syntax magic to do something like:
kindergarden=0 if its<0 # ← no need to repeat the var name?
It would be cool especially with long var names, or on arrays
with long
indices!
bye!
Dominik
This communication (including any attachments) contains confidential information. If you are not the intended recipient and you have received this communication in error, you should destroy it without copying, disclosing or otherwise using its contents. Please notify the sender immediately of the error.
Internet communications are not necessarily secure and may be intercepted or changed after they are sent. Abbey National Treasury Services plc does not accept liability for any loss you may suffer as a result of interception or any liability for such changes. If you wish to confirm the origin or content of this communication, please contact the sender by using an alternative means of communication.
This communication does not create or modify any contract and, unless otherwise stated, is not intended to be contractually binding.
Abbey National Treasury Services plc. Registered Office: Abbey National House, 2 Triton Square, Regents Place, London NW1 3AN. Registered in England under Company Registration Number: 2338548. Regulated by the Financial Services Authority (FSA).
This only assigns if kindergarden is nil or false. The OP wanted <0 as
condition.
I think, with <0 it can’t be done without mentioning the variable twice,
since assignment always needs an lvalue on the left and the condition
needs the variable, too.
Is there any super cool syntax magic to do something like:
kindergarden=0 if its<0 # ← no need to repeat the var name?
It would be cool especially with long var names, or on arrays
with long
indices!
bye!
Dominik
This communication (including any attachments) contains confidential
information. If you are not the intended recipient and you have received
this communication in error, you should destroy it without copying,
disclosing or otherwise using its contents. Please notify the sender
immediately of the error.
Internet communications are not necessarily secure and may be
intercepted or changed after they are sent. Abbey National Treasury
Services plc does not accept liability for any loss you may suffer as a
result of interception or any liability for such changes. If you wish to
confirm the origin or content of this communication, please contact the
sender by using an alternative means of communication.
This communication does not create or modify any contract and, unless
otherwise stated, is not intended to be contractually binding.
Abbey National Treasury Services plc. Registered Office: Abbey National
House, 2 Triton Square, Regents Place, London NW1 3AN. Registered in
England under Company Registration Number: 2338548. Regulated by the
Financial Services Authority (FSA).
Well, yeah; that was my point. =) His subject asked (or at least
implies) about setting a var if it’s not set, for which “||=” is
perfect. But his example asks about setting something to 0 if it’s
not 0 already (< 0, i.e. negative), which is somewhat different.
The code you used in irb doesn’t quite make sense. (To me, anyway,
and evidently to ruby as well.) “kindergarden<0” is a boolean
expression, not a (var) name.
···
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!