Intro Flashcards

Familiarize yourself with intro level elements of Ruby (58 cards)

1
Q

What provides ordered, integer-indexed collections of any object?

A

An Array

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

How should text be formatted in Classes?

A

CamelCase

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

How should text be formatted in methods, arguments and variables?

A

in_snake_case

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

How should text be formatted in constants?

A

IN_SNAKED_UPPERCASE

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

How is a ternary operator structured?

A

puts Boolean ? “expression if true” : “expression if false”

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

What is a shortcut for creating an array of strings?

A

array_name = %w{“string”, “string”, “string”}

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

What is a shortcut for creating hashes?

A

hash_name = {key: ‘value’, key: ‘value’}

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

How would you use the .each block to access data in a hash?

A

hash_name.each { | key, name | puts “#{name} => #{value}”}

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

What does this produce?
a = %w( ant bee cat dog fish)
a.each { |animal| puts animal}

A
and
bee
cat
dog
fish
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are instance variable names led with?

A

They are lead with the @symbol

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

The controller passes off heavy code to what?

A

The model

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

What are the 4 major classes and objects in Ruby

A

Arrays, Hashes, Objects and Methods

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

What is the operator called?

A

The spaceship operator

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

Where does Rails look to find the current layout?

A

Rails first looks for a file in the app/views/layouts with the same base name as the controller

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

What does the following method do:

redirect_to

A

Tells the browser to send a new request for a different URL

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

What are the five types of variables in Ruby?

A

Local, Instance, Class, Constants and Global

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

What is the blueprint from which individual objects are created?

A

A class

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

What does IRb stand for?

A

Interactive Ruby

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

What is IRb?

A

A shell for experimentation in which you can immediately view expression results, line by line.

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

What is an identifier?

A

Identifiers are names of variables, constants, and methods and are case sensitive.

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

What are variables?

A

They are memory locations which holds any data to be used by any program.

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

What is a Global variable?

A

A variable that is accessible in every scope

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

What is a Class variable?

A

A variable defined in a class of which a single copy exists, regardless of how many instances of the class exist

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

What is the scope of a Local variable?

A

The scope of a local variable ranges from class, module, def, or within a { } or ‘do/end’ block

25
What is an Instance variable?
A variable defined in a class and only affect the object that contains it.
26
What methods pints text to the screen? What are the differences?
Puts & Prints. Puts creates a new line where prints stays on the same line.
27
What is scope?
The determining factor on where variables can be accessed.
28
Which character denotes a global variable?
It is denoted by the $ character.
29
What do reserved words do?
Reserved words that tell the Ruby interpreter what to do.
30
What is domain modeling
The process of figuring out how the real world is represented in an object oriented program.
31
Which character denotes an instance variable?
It is denoted by the @ character.
32
What does a ban method do to a string?
Modifies the receiver in place using the ! character.
33
What string method tells you the number of characters in a string?
.length
34
What method will provide a random number between 0-50
rand(50)
35
What is the name for the position of an item in an array?
An index
36
What does the unshift method do to an array?
Prepends items to the beginning of an array.
37
What is the term for a loop that doesn't end?
An infinite loop
38
What keyword repeats the current iteration of a loop?
redo
39
What does the 'break' keyword do in a loop?
It ends the loop when a condition is met
40
What keyword goes to the next item in a loop?
The 'next' keyword
41
What does the ensure block do?
Ensures the code within it gets run regardless of errors.
42
What does the yield keyword do?
Runs the block
43
What symbol tells a Ruby method to expect a block?
The & symbol
44
What will the last statement of a block of code be?
The return value
45
What are prods & lambdas?
Blocks of code assigned to variables. Can be passed to different methods and the scope can change.
46
What are modules?
Modules serve as containers for data, classes, methods, or even other modules. Modules are useful for sharing behavior between classes and frequently used for namespacing classes and constants.
47
What keyword includes a module in a class?
The 'include' keyword.
48
What is the difference between include and extend?
Extend operates on the class, include operates on the instance.
49
What symbols are used to access methods and constants inside of a module?
The :: symbols
50
What keyword creates a module?
Module
51
What method must you define to take advantage of the Comparable module?
The rocket ship method
52
How would you create a new date?
Date.new(yyyy, mm, dd)
53
What method must be defined when including the Enumerable module?
the .each method
54
What is refactoring?
Improving the structure or appearance of our code without changing what it actually does.
55
What is the conditional assignment operator?
||=
56
what attribute comes before a method_name?
the 'def' attribute
57
What does CRUD stand for
Create, Read, Update, Destroy
58
What does MVC stand for
Model-View-Controller