Intro Flashcards

Familiarize yourself with intro level elements of Ruby

You may prefer our related Brainscape-certified flashcards:
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
Q

What is an Instance variable?

A

A variable defined in a class and only affect the object that contains it.

26
Q

What methods pints text to the screen? What are the differences?

A

Puts & Prints. Puts creates a new line where prints stays on the same line.

27
Q

What is scope?

A

The determining factor on where variables can be accessed.

28
Q

Which character denotes a global variable?

A

It is denoted by the $ character.

29
Q

What do reserved words do?

A

Reserved words that tell the Ruby interpreter what to do.

30
Q

What is domain modeling

A

The process of figuring out how the real world is represented in an object oriented program.

31
Q

Which character denotes an instance variable?

A

It is denoted by the @ character.

32
Q

What does a ban method do to a string?

A

Modifies the receiver in place using the ! character.

33
Q

What string method tells you the number of characters in a string?

A

.length

34
Q

What method will provide a random number between 0-50

A

rand(50)

35
Q

What is the name for the position of an item in an array?

A

An index

36
Q

What does the unshift method do to an array?

A

Prepends items to the beginning of an array.

37
Q

What is the term for a loop that doesn’t end?

A

An infinite loop

38
Q

What keyword repeats the current iteration of a loop?

A

redo

39
Q

What does the ‘break’ keyword do in a loop?

A

It ends the loop when a condition is met

40
Q

What keyword goes to the next item in a loop?

A

The ‘next’ keyword

41
Q

What does the ensure block do?

A

Ensures the code within it gets run regardless of errors.

42
Q

What does the yield keyword do?

A

Runs the block

43
Q

What symbol tells a Ruby method to expect a block?

A

The & symbol

44
Q

What will the last statement of a block of code be?

A

The return value

45
Q

What are prods & lambdas?

A

Blocks of code assigned to variables. Can be passed to different methods and the scope can change.

46
Q

What are modules?

A

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
Q

What keyword includes a module in a class?

A

The ‘include’ keyword.

48
Q

What is the difference between include and extend?

A

Extend operates on the class, include operates on the instance.

49
Q

What symbols are used to access methods and constants inside of a module?

A

The :: symbols

50
Q

What keyword creates a module?

A

Module

51
Q

What method must you define to take advantage of the Comparable module?

A

The rocket ship method

52
Q

How would you create a new date?

A

Date.new(yyyy, mm, dd)

53
Q

What method must be defined when including the Enumerable module?

A

the .each method

54
Q

What is refactoring?

A

Improving the structure or appearance of our code without changing what it actually does.

55
Q

What is the conditional assignment operator?

A

||=

56
Q

what attribute comes before a method_name?

A

the ‘def’ attribute

57
Q

What does CRUD stand for

A

Create, Read, Update, Destroy

58
Q

What does MVC stand for

A

Model-View-Controller