TerryP
11/23/2007 3:41:00 AM
Martin Durai wrote:
> How to use logical operators in ruby?
>
> Logical AND, OR, NOT..
>
> In other languages like java &&, ||, ! is used. how we have to use it in
> ruby.
>
> A sample code in java, please explain it in ruby.
>
> if((namespace == attributeUri[ i ] ||
> namespace.equals(attributeUri[ i ]) )
> && name.equals(attributeName[ i ]) )
>
> Please do the same in ruby
>
> Thanks in advance
It's just a matter of preference, use english or C-style symbols. The C-Stye
has precedence over the keyword versions (e.g. || rather then 'or' ).
Operators and Precedence (Top to bottom)
:: .
[]
**
-(unary) +(unary) ! ~
* / %
+ -
<< >>
&
| ^
> >= < <=
<=> == === != =~ !~
&&
||
... ...
=(+=, -=...)
not
and or
All of the above are just methods except these:
=, ::, ., .., ..., !, not, &&, and, ||, or, !=, !~
In addition, assignment operators(+= etc.) are not user-definable.