ROR学习系列5-Ruby基础4-Ruby中的运算符

因为比较简单,直接看代码了
value = 3
puts value
value = value + 3   #addition
puts value
value = value / 2   #division
puts value
value = value * 3   #multiplication
puts value
value = value ** 2  #exponentiation
puts value
现在看一下输出结果:
3
6
3
9
81
下面是Ruby中的运算符:
Operator    Description

[ ]         Array reference
[ ]=        Array element set

**          Exponentiation

!           Not
~           Complement
+           Unary plus
-           Minus

*           Multiply
/           Divide
%           Modulo

+           Plus
-           Minus

&&          Logical And

||          Logical Or

..          Inclusive range
...         Exclusive range

?           Ternary if
:           Else

>>          Right shift
<<          Left shift

&           Bitwise And

^           Bitwise exclusive Or (Xor)
|           Regular Or

Comparison operators:
<=          Less than or equal to
<           Less than
>           Greater than
>=          Greater than or equal to

Equality and pattern match
<=>         Less than, equal to, greater than
==          Equal to
===         Tests equality in a when clause of a case statement
!=          Not equal to
=~          Regular expression pattern match


Assignment
=           Normal assign
%=          Modulus and assign
/=          Divide and assign
-=          Subtract and assign
+=          Add and assign
*=          Multiply and assign
**=         Exponent and assign

defined?    True if symbol defined
not         Logical negation
and         Logical composition
or

Statement modifiers
if
unless
while
until

begin/endBlock expression






你可能感兴趣的:(Ruby)