Ruby Flashcards

(63 cards)

0
Q

What is an index?

A

Each item in an array. It begins and 0 and continues counting in increments of 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

In this array what position does the number 400 hold?

[100, 200, 300, 400, 500]

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does // array[2] // mean?

A

It is asking for the 3rd index item in an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are arrays of arrays called?

A

Multidimensional arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A built in module for mathematics

A

Math

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

One role of a module is to…

A

group together similar methods under one familiar name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

a period or dot is used to…

A

identify the receiver of a message

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

def

A

how we DEFINE a method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

end

A

tells Ruby we are done with whatever we were defining

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

{ }

A

Ruby’s way of inserting something into a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

==

A

is equal to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

!=

A

is not equal to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

.include?

A

evaluates to true if it finds what it’s looking for and false otherwise

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

.gsub!

A

global substitution - replaces every instance of something with something else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

+=, -=, *=, and /=

A

increment or decrement by a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

iterator

A

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!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

number.times

A

quick way to do something over and over…

10.times { print “Chunky bacon!” }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

.split()

A

takes a string and returns it as an array separated by what ever you give it (commas, spaces, etc.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

multidimensional arrays

A

arrays within arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Histogram

A

A visual representation of data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

|=

A

conditional operator - can use to assign a variable ONLY if it has not already been assigned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

implicit return

A

ruby will return the LAST evaluated expression whether or not you specifically ask it to “return” something to you

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

&&

A

returns true when both sides are true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
||
returns true when one or other or both sides are true
26
n.times { }
can specify to do the thing inside the block "n" number of times
27
.each
iterates through a collection and looks at each item
28
.even?
checks if number is even evaluates to true
29
.upto
to print out an ascending range of values Example: 95.upto(100) {|num| print num, " "} letters too!!
30
.downto
to print out a descending range of values 95.downto(85) {|num| print num, " "} letters too!
31
.respond_to?
takes a symbol and returns true if an object CAN receive that method and false otherwise Example: [1, 2, 3].respond_to?(:push)
32
.push OR
adds a value to the end of an array OR to the end of a string
33
.to_s?
changes item to a string
34
string interpolation
``` #{ } Example: drink = coffee I love #{drink} in the mornings. ```
35
one line if statement for: | if one is less than two puts "something"
if 1
36
x**2
returns the square of a number
37
refactoring
improving the code's structure, appearance and performance without modifying overall behavior
38
do one line "if" and "unless" statements need "ends"?
No
39
give a definition of a ruby block
a bit of code to be executed
40
name the two ways that ruby blocks start and end
curly braces { } OR do..end
41
blocks CAN be combined with methods like .each and .times to ...
complete an action for each element in a collection
42
.collect
``` takes a block and applies it to every element in an array Example: my_nums = [1,2,3] my_nums.collect {|num| num**2} ==> [1,4,9] ```
43
# Fill in the blanks ``` def double( ___) yield(___) puts "This is a method including a yield" ``` double(___) {|n| puts n*2}
n, n, 9 instead of 9 any number would do
44
to pass a proc to a method that normally would expect a block you must use the ____ sign in front of the saved proc
& sign Example: [4,5,6].map!(&cube) ==> [64, 125, 215]
45
.call
calls a proc
46
proc/lambda - name 2 differences
lambda check the number of arguments given to it, proc does not lambda returns and passes control back to calling method/proc returns immediately without going back
47
command line - ls
list directories
48
command line - pwd
print working directory - shows you where you currently are
49
command line - cd
change directory
50
command line - cd ..
change one level up in the directory
51
command line - mkdir
make directory
52
command line - touch
creates a new file in teh working directory
53
command line - -a
an option that modifies the behavior of ls. tells it to also list all contents including hidden files and directories (those starting with a .)
54
command line - -l
option modifying ls. tells it to list all contents in long format
55
command line - -t
option modifying ls. tells it to order files and directories by time last modified
56
command line - -alt
a combination of options (a) (l) (t). multiple options can be typed together
57
command line - cp
copies files or directories | cp frida.txt lincoln.txt copied the contents from frida into lincoln
58
how to use command line cp
cp foldername/filename newfilename AND cp foldername/filename foldername/filename newfile name
59
cp * foldername/
the * selects groups of files. it is known as a wildcard. It selects all files in the working directory
60
command line - mv | as a mover
moves files and directories | mv filename.txt foldername/
61
command line -mv | as a copier
mv batman.txt spiderman.txt | renames batman to spiderman
62
command line - rm
removes files and directories - PERMANENT!
63
command line - rm -r
modifies rm command. stands for recursive. says delete directory and all child directories -PERMANENT!