Everything Ruby Flashcards
With what methods can you print to the ruby console?
Using puts, print, and p
What is the puts method?
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.
What is the p method?
The p method will print the object in its code form.
What is the print method?
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 do you get user input from the user?
With gets and chomp methods.
What is the gets method?
the gets method will prompt the user to give a input, it will however add a /n to the string or integer.
What is the .chomp method?
The .chomp method gets rid of the character: \n at the end of the line
What kind of variables are there?
- Local variables
- Global variables
- instance variables
- Constants
- Class variables
What is a local variable?
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
What is a global variable?
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.
What is an instance variable?
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.
What is an constant?
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.
What is a class variable?
Class variables ($$variable_name) are variables that are only used in a specific class. They are rarely used in practical situations.
What is a string?
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
What is string interpolation?
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.