Ruby Flashcards
What is an index?
Each item in an array. It begins and 0 and continues counting in increments of 1.
In this array what position does the number 400 hold?
[100, 200, 300, 400, 500]
3
What does // array[2] // mean?
It is asking for the 3rd index item in an array.
What are arrays of arrays called?
Multidimensional arrays
A built in module for mathematics
Math
One role of a module is to…
group together similar methods under one familiar name
a period or dot is used to…
identify the receiver of a message
def
how we DEFINE a method
end
tells Ruby we are done with whatever we were defining
{ }
Ruby’s way of inserting something into a string
==
is equal to
!=
is not equal to
.include?
evaluates to true if it finds what it’s looking for and false otherwise
.gsub!
global substitution - replaces every instance of something with something else
+=, -=, *=, and /=
increment or decrement by a value
iterator
An iterator is just a Ruby method that repeatedly invokes a block of code. The code block is just the bit that contains the instructions to be repeated, and those instructions can be just about anything you like!
number.times
quick way to do something over and over…
10.times { print “Chunky bacon!” }
.split()
takes a string and returns it as an array separated by what ever you give it (commas, spaces, etc.)
multidimensional arrays
arrays within arrays
Histogram
A visual representation of data.
It returns 0 if the first operand (item to be compared) equals the second, 1 if first operand is greater than the second, and -1 if the first operand is less than the second.
|=
conditional operator - can use to assign a variable ONLY if it has not already been assigned.
implicit return
ruby will return the LAST evaluated expression whether or not you specifically ask it to “return” something to you
&&
returns true when both sides are true
||
returns true when one or other or both sides are true