Ruby characters Flashcards
puts
Shows whatever comes next and inserts a line break
” “ - double quotes
Defines what will be written to the screen.
- hashtag
Leaves comments that will not be read by the code.
+ - plus
Addition between numbers
- minus
Subtract between numbers
/ - slash
Division between numbers
- asterisk
Multiplication between numbers
% - moduls
Grabs the remainder after a division
Determines if number on left is less than on the right
>
- great than
Determines if number on left is greater than on the right
Determines if number on left is less than OR eaqual to number on the right
> = - greater than equal
Determines if number on left is greater than OR eaqual to number on the right
x = - variable
Sets the string on the left to whatever is on the right. Can use these in functions or in quotes.
_ - underscore
Used to add a space when that is not allowed, ex. in variable names, or functions
{x} - ?
Used with double quotes to use variables previously stated
Command to write variables and text to the screen WITHOUT adding a new line at the end
formatter
I have no idea
\n - backslash n (escape)
New line character
””” - triple quotes
Put at the beginning and end to write a bunch of text over several lines.
\ - backslash (escape)
Allows the backslash to be read as a stand alone character instead of an escape
' - Single Quote (escape)
Allows the single quote to be read as a stand alone character instead of an escape
" - Double quote (escape)
Allows the double quote to be read as a stand alone character instead of an escape
\a - bell (escape)
?
\b backspace (escape)
?
\f - formfeed (escape)
?
\n - linefeed (escape)
Creates a new line inside quotes
\r - carriage return (escape)
?
\t - horizontal tab
Creates a tab inside quotes
\uxxxx - 16-bit hex value (escape)
?
\v - vertical tab (escape)
Inserts a vertical tab inside quotes
\ooo - octal value (escape)
?
\xhh - hex value (escape)
?
gets
Prompts input, and sets it to a variable name
.chomp
removes any escapes
.to_i
Used to turn something into an integer
ARGV - argument variable
Assigns variables by whatever is opened in the terminal. It is assigned from left to right.
prompt
Prompts users for input? Can set with ‘=’ what should be shown.
open() - command
Will open whatever file is placed inside the parentheses
.read (command)
Reads the contents of the file. You can assign the result to a variable.
.close (command)
Command to close a file
.readline (command)
Reads just one line of a text file
.truncate (command)
Empties the file. Watch out if you care about the file.
.write(‘stuff’) (command)
Writes “stuff” to the file.
‘w’ -
Used with the open(file, ‘w’) in order to open the file to be written.
‘r’
Used with the open(file, ‘r’) in order to open the file to be read.
target.write(x)
x is whatever you’d like to write
def
Starts a function
function function_name(arg1, arg2)
a small program that you set, and then can call back. Can set the arguments in many different ways.
end
Closes a function
seek(0)
Will set the writing cursor to the very beginning of a document.
+=
a = a + b
return
Sets a variable to a be a value from a function