Ruby basics + advanced Flashcards
What is ruby?
It is a programming language
What does RVM stand for?
Ruby version manager
What does RVM let you do?
It lets you switch between different versions of ruby.
What are variables?
They are the building blocks of a program and they let you store information.
How much information can a variable store?
Variables can store a lot of data, full algoritms, blocks and lambdas
How do you set a variable in ruby?
you give it a name and set it equal to the information
ex variable_1 = ‘A string’
How can you print out objects to the terminal?
- puts
- p
What is puts?
puts will return nil and print out the object in a new line. Puts also iterates over the values.
What is p?
p will return the value and print out the object
How do you get user input form the terminal?
you use the gets method
What is chomp?
chomp deletes the extra character that your gets method adds to the input.
What kinds 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 limits itself to a local scope of where it is declared.
It is only available to that specific method or package
What is a global variable?
A global variable written with a $ before the variable name is available all over the application. And it’s a terrible idea. because the last time you set the variable will declare it.
What is a instance variable?
An instance variable is written with a @ sign before the variable name.
The instance variable is available for that instance in other places.
What is a constant?
A constant is a variable is written with CAPITAL letters and is a variable that is not supposed to be changed.
What is a class variable?
A class variable is written with @@ is a variable that is available to that instance of the class.
What is a string?
A string is a object where you store a collection of characters. These must be contained in single or double quotes
What is string interpolation?
String interpolation is a method where you can display dynamic values inside a string. Everything between a #{ } will be embedded ruby. You must use double quotes on the string when working with string interpolation.
What is string manipulation?
String manipulation is when you use methods to change the strings.
what is a bang? ( ! )
When you see the ! in the end of a method it means that it is changing the original version of the variable .
What is string substitution?
String substitution is a method in ruby. You use .gsub!( ‘original’ , ‘the change’)
What is the strip method?
it removes the extra spaces in a string in the beginning and in the end of a string
What is the split method?
The split method converts each word in a string to an array.