All Flashcards

1
Q

What are variables?

A

Variables are assigned values that use the = symbol. The value on the left now represents the data on the right. For example, x= “hello” if we type x into the terminal, we will recieve the value “hello”

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

What does .each do when used in a loop?

A

.each is a built in iterator. It loops through each item in a list, hash, or other iterable object allowing you to perform operations on that value. The block of an .each statement creates a new scope for your variable so you don’t accidentally modify the original value.

one_to_ten = (1..10).to_a
one_to_ten.each do |num|
print (num**2).to_s + “ “
end

1 4 9 16 25 36 49 64 81 100

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

What does .times do when used in a loop?

A

It performs an action a given number of times.

3.times do
puts “I’m in the loop!”
end
puts “I’m out the loop!”

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

How do we create a ternary statement out of this if/then statement?

grade = 88
if grade >= 70 then
puts "pass" 
else
puts "fail"
A

syntax:
boolean expression ? true expression : false expression.

grade = 88

status = grade >= 70 ? “pass” : “fail”

=> pass

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

What is a String?

A

Strings are used for storing and manipulating text. They are written between quotation marks. Both single and double quotes at each end of a string must match.

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

What’s the difference between puts and prints?

A

Puts is short for “put string” The primary difference between them is that puts adds a newline after executing, and print does not.

3.times { print “Hello!” }
Hello!Hello!Hello!

3.times { puts “Hello!” }
Hello!
Hello!
Hello!

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

What is a method?

A

A Method is used to create parameterized, reusable code. Ruby methods have to start with a “def” and end with an “end”

def method_name(arguments)
  # Code to be executed
end

def sum(x,y)
x + y
end

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

What is a while loop?

A

A while loop will execute a block of code as long as its condition is true. When the condition becomes false, the code after the end of the loop will be executed.

Syntax: while condition_is_true
  # do something
end
Example: 
i = 1
while i < 5
  puts "#{i} is less than 5!"
  i += 1
end
puts "Done!"
1 is less than 5!
2 is less than 5!
3 is less than 5!
4 is less than 5!
Done!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an Until Loop?

A

An until loop will execute a block of code as long as its condition is false. When the condition becomes true, the code after the end of the loop will be executed.

Syntax:
until condition_is_false
# do something
end

Example:
counter = 3
until counter

3
2
1
Blast off!

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

What is a ‘for’ loop?

A

The for loop is used to iterate an object. The Ruby .each method is preferred over the for loop because the for loop does not create a new scope for the object whereas the .each method does. The for loop is rare in Ruby.

Syntax:
for iterator in iterable_object
# do something
end

Example:
for number in (0..5)
puts number
end

0
1
2
3
4
5
Example: 
my_array = ["Matz", "chunky", "bacon"]
for item in my_array
  puts item
end

Matz
chunky
bacon

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

How does and if, elsif and else statement work?

A

If statements are Boolean expressions and are used to in methods and only run if true.

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

How does an unless statement work?

A

An unless statement is the opposite of and if statement. It runs if the boolean expression runs false.

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

True or False: When creating a class, you use CamelCase as the naming convention.

A

TRUE.

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

True or False: When you daisy chain methods together, the last one returns your value.

A

TRUE.

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

True or False: Classes inherit other classes.

A

TRUE.

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

How do you create a new instance of a class?

A

variable = Class.new

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

When creating a new instance of a class, and we use .new - what is the naming convention of the data before .new?

A

The word must be upper case. For example: x = Class.new. That creates a new instance of the class.

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

What do we use in hashes that represent our data?

A

keys.

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

How do we create a new hash?

A

by assigning a variable to Hash.new. Example: x = Hash.new

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

How would we assign a father, mother, brother to a hash?

A
family = Hash.new
family = {father: "Mike", mother: "Mary Kay", brother: "John"}

calling a hash can look like this:

family[:husband] = “Christian”

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

What does array.unshift do?

A

It adds an item to the beginning of that array.

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

What does array.pop do?

A

Pop removes the last element in an array.

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

What does array.shift do?

A

It removes the first item in an array.

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

How do we create a new array?

A

We use Array.new. for example: x = Array.new

25
What is data assigned to in Arrays?
To integers. Arrays use integers to index data. Hashes use keys. array[0] = "0" array[1] = "hello"
26
How do we see what keys are in our hash?
We use .keys. For example: family.keys :father, :mother, :brother, :husband
27
How do we see what values are in your hash?
We use .values. For example: family.values "Mike", "Mary Kay", "John"
28
Can you have an array in your hashes?
Yes.
29
How do you build an array in your hash?
By assigning the array to a key. :brother = ["John", "Frank"]
30
What does array.push do?
It adds whatever variable you pass through it, into the array. For example: array.push(4) adds "4" to your array
31
Is delete_at a destructive change?
Yes. if you pass the number of the index you wan to delete, it will permanently delete it. for example: array.delete_at(4) will delete the 4th index of your array.
32
What does array.slice do?
It will slice out the value assigned to whatever index you pass through it. for example: array.slice 1 will return to you whatever data is assigned to index 1.
33
What does array.slice! do?
array.slice! 1 will slice and delete the value assigned to the array. This is a destructive change.
34
What does array.length do?
It tells you how many indexes are in your array.
35
What does array.count do?
It counts how many indexes are in your array.
36
What does array << do?
It will append all values together in the array. Just like .push does.
37
What does array << "hello" do?
It appends "hello" to the end of the array, assigning it to the corresponding index.
38
How can we see all of the methods available to use in an array?
array.methods
39
What does CRUD stand for?
create, read, update, destroy.
40
What does DRY stand for?
Don't Repeat Yourself..
41
In rails - specfically, the MVP - what does the Controller do?
It creates the relationship between the Model and the Viewer.
42
When we set up a scaffold for our rails app - does it create a database file for you?
YES.
43
If you want to add fields to your app before you create it, can you do that when you set up your scaffold?
YES.
44
What symbol do we have to put at the end of every SQL command?
; | Semicolon
45
What does SQL stand for?
Structured Query Language
46
When we want to start working in a rails app, what do we need to do?
Root into the folder it's created and then run the rails console using rails c
47
What do we call methods in Rails?
Commands
48
True or False: An 'instance' in an object generated from a class.
True
49
When interacting with the database in the Rails Console, you are?
issuing commands in Ruby
50
You can access local host on your browser, but only if...
you have the rails console for that app running in your terminal.
51
When we create a scaffold, it automatically creates a controller named after our scaffold. It's located where?
apps/controllers directory. example: if our scaffold was called "Books" it would create a BooksController directory.
52
When we create a scaffold, it automatically creates a controller class named after our scaffold. It's inherited from where?
from the ApplicationController class. example: books_controller.rb in the BooksController directory in the apps/controllers directory.
53
True or False: SQL always exists in plurality.
TRUE
54
Once you've created a new Git project on github you add your code from the terminal with...
git remote add origin http:// (git url)
55
What do we use in the Rails console to copy?
cp
56
What does erb stand for?
embedded ruby.
57
What does it mean when there is an erb file that is started with an underscore?
It's a partial.
58
True or False: A helper is a module and can be shared across all controllers.
TRUE.
59
The initial scaffolding process provides an interface to this data. Because the scaffold process uses the supplied list of fields to create both the fields where?
in the database, and the fields in the web interface