programming ruby - 4

Operator Expressions

If you enclose a string in backquotes (sometimes called backticks), or use the delimited form prefixed by %x, it will (by default) be executed as a command by your underlying operating system.

 

1.8 In Ruby 1.8, the value of the assignment is always the value of the parameter; the return value of the method is discarded.

 

Any value that is not nil or the constant false is true.

 

=== Used to compare the each of the items with the target in the when clause of a case statement.

 

eql? True if the receiver and argument have both the same type and equal values. 1 == 1.0 returns true, but 1.eql?(1.0) is false.

 

equal? True if the receiver and argument have the same object ID.

 

The operators and, or, && and || actually return the first of their arguments that determine the truth or falsity of the condition. Sounds grand.What does it mean?
Take the expression “val1 and val2”. If val1 is either false or nil, then we know the expression cannot be true. In this case, the value of val1 determines the overall value of the expression, so it is the value returned. If val1 has some other value, then the overall value of the expression depends on val2, so its value is returned.

 

You can get even terser and use a colon ( : ) in place of the then.

 

break terminates the immediately enclosing loop; control resumes at the statement following the block. redo repeats the loop from the start, but without reevaluating the condition or fetching the next element (in an iterator). next skips to the end of the loop, effectively starting the next iteration.

 

The redo statement causes a loop to repeat the current iteration. Sometimes, though, you need to wind the loop right back to the very beginning. The retry statement is just the ticket. retry restarts any kind of iterator loop.

你可能感兴趣的:(programming)