Ruby: Symbol Review Flashcards
\
Escape sequence for string: Escapes the “" character.
'
Escape sequence for single-quoted string. Escape the single quote character.
"
Escape sequence for double-quoted string. Escape the double quote character.
\n
Escape sequence for double-quoted string. Starts a new line.
\s
Escape sequence for double-quoted string. Adds a space.
\t
Escape sequence for double-quoted string. Adds a tabbed space (~5 spaces)
\b
Escape sequence for double-quoted string. Deletes a space (backspace function). In IRB, only works with puts.
\a
Escape sequence. Sends an alert to the user. The alert may be dependent on the user’s computer - it may flash, be an audio alert, etc.
\f
Escape sequence. Begins a new line at the same point as the previous line ended.
example: puts “Hello\fWorld”
Hello
World
=> nil
\v
Escape sequence. Begins a new line at the same point as the previous line ended.
example: puts “Hello\fWorld”
Hello
World
=> nil
..
The two dot construction for a Ruby Range means INCLUSIVE of the final character.
Example:
(1..10)
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
…
The three dot construction for a Ruby Range means EXCLUSIVE of the final character.
Example:
(1…10)
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
||
Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. Same as ‘or’ operator.
Example:
(a || b) is true.
&&
Called Logical AND operator. If both the operands are non zero then then condition becomes true. Same as ‘and’ operator.
Example:
(a && b) is true.
not
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
Example:
not(a && b) is false.
!
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
Example:
!(a && b) is false.
or
Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. Same as ‘||’ operator.
Example:
(a or b) is true.
and
Called Logical AND operator. If both the operands are true then then condition becomes true. Same as ‘&&’ operator.
Example:
(a and b) is true.
+
Addition - Adds values on either side of the operator.
Example:
a + b will give 30
-
Subtraction - Subtracts right hand operand from left hand operand.
Example:
a - b will give -10