different symbols and functions Flashcards
Define % and what it’s used for
% is a module used to find how many times a number can go into another. fro example 4 % 2 = 0 and 5 % 2 = 1.
Define ! and how it’s used
The symbol ! is = to “not”
For example num != 0 or num is not equal to 0.
or
if (num % 3) == 0 && !(num % 5 == 0)
Define ==
== is when you want to know if 2 variables are the same.
for example if num = 32
num == 32 then this is true
but
if
num == 22 then this is false
Define <=
less than or equal to
Define >=
Greater or equal to
Define >
Greater then
Define <
Less then
Define [] and what its used for
It gets the index in an array
For example
num[“hello”, “no”, “yes”]
num[2] would equal to “yes”
Define .length
.length is used to get the length of a string or and array
Define .chr
.chr is equal to a character of a string
Define i
i is used to define a number
i = 0
what are the Booleans in Ruby
in Ruby there are 2 Boolean values, true and false
How does an ‘if’ statement work?
if statement executes code if the Boolean is equal to ‘true’
Define def and return
def defines a method and return exits a method
Define elsif statement and what it does
elsif is a conditional statement that pairs with a previous if statement, it takes on a Boolean expression if the previous was false, for it to run the Boolean expression now has to be true.
Define ‘while’ and waht it does
while is a loop that you use to give an order as long as its true, if false it executes code after the end loop
Define .push() and how it works
.push() can add multiple data into an array while «_space;can only add 1 per time
Define .pop() and how it works
.pop() takes away the last data in the array and is also now equal to it
Define .unshift() and how it works
.unshift() adds data to the front of the array, it must include a parameter
Define .shift() and how it works
.shift() takes away first data of an array
Define .index() and how it works
.index gets the index of an array for Ex: array.index(“Hello”)
array = [“hello”, “no”] puts array.index(“llo”) would give us 2
Define .include?() and how it works
.include?() is going to give you a boolean checking if the variable exist in an array of data
Define array.pop()
array.pop() takes away the last data entry of an array
Define array.push()
array.push() gets a parameter and includes it in the back of an array. you must include a parameter
define array.reverse()
it gives you the reverse data but it does not save it.
define array.reverse!()
if you want to change the array and keep it that way, you can use this method to reverse and save the data.
How to use a range and what symbols to use
a range of an array helps you get the data of an array between a certain index, if used like this [0..3] it will get the dat from 0-3 but if yuo use 3 dots,
[0…3] it gets all the data from 0 to not including 3.
define .split() and how it works
str.split() is used when you want to take variables away in a string. by doing this you can now turn that string into an array.
define array.join()
by doing this method you can turn an array into a string.
explain .each , .each_char and .each_with_index
&& .each_char.with_index
explain .times