Everything Ruby Flashcards

1
Q

With what methods can you print to the ruby console?

A

Using puts, print, and p

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

What is the puts method?

A

The puts method will return a value to you and display it by printing each object in a new line. The puts method iterates through the objects and displays individual values.

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

What is the p method?

A

The p method will print the object in its code form.

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

What is the print method?

A

The print method will return a value to you and display it by printing each object. The print method iterates through the objects and displays individual values.

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

How do you get user input from the user?

A

With gets and chomp methods.

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

What is the gets method?

A

the gets method will prompt the user to give a input, it will however add a /n to the string or integer.

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

What is the .chomp method?

A

The .chomp method gets rid of the character: \n at the end of the line

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

What kind of variables are there?

A
  • Local variables
  • Global variables
  • instance variables
  • Constants
  • Class variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a local variable?

A

A local variable is a variable that is declared inside a method or a loop. The scope is that it is limited to only that method or loop

Undefined local variable or method

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

What is a global variable?

A

A global variables is a variable that is available for the entire application everywhere you write it with a $ before the variable name. Not a good idea to use them because they are hard to keep track of.

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

What is an instance variable?

A

An instance variable (@variable_name) is only available in during a particular occurance and it is not available in other methods.

Why not make it a local variable? Beacuse we want to call the method in other files, for that to happen we need to use an instance variable .
Ex view and controller.

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

What is an constant?

A

Generally constants are values that do not change.
You use all capital letters when declaring constants like PI = 3,14
Ruby does allow you to change a constant but it is poor programming practice to change constants.

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

What is a class variable?

A

Class variables ($$variable_name) are variables that are only used in a specific class. They are rarely used in practical situations.

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

What is a string?

A

A string is a data type which contains a set of characters, often a word or sentence. They need to be wrapped inside quotation marks

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

What is string interpolation?

A

It is the ability to integrate dynamic values inside a string. They are enclosed with a #{ } you can even run code you want to display inside the brackets. But it is not recommended to type entire methods with string interpolation.

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

What is string manipulation?

A

String manipulation is to alter the format or the value of a string.
Methods like upcase, downcase is used.

17
Q

What is method chaining?

A

It is when we join multiple methods and use them.

18
Q

What is string substititon

A

It is when you change a value in the string. We use the gsub method. which stands for global substitution

19
Q

Why does one add a bang?

A

Adding a bang permenantly changes the the object with the changes.

20
Q

What is the strip method?

A

The strip method takes away the spaces in the beginning and the end of a string.

21
Q

What is the split method?

A

The split method takes a string and turns it into an array