Exercise #1
In your prework gist, answer the following questions regarding the string, “Turing”. What ruby command would we use to get:
1. The “T” from “Turing”.
"Turing"[0]
2. The length of “Turing”.
"Turing".length
3. Make the whole string capital letters.
"Turing".upcase
4. Delete the “n” from “Turing”.
"Turing".delete("n")
5. Assign “Turing” to a variable.
turing = "Turing"
Exercise #2
In your prework gist, answer the following questions:
1. What does gets do?
A method, gets, retrives the user's response in a string format.
2. What is the difference between the input without the .chomp and the input with the .chomp?
will strip your text of any newlines, or carrige returns at the end
Input without .chomp returns the new line created when the user enters a value and presses return. Input with .chomp strips out any new lines created, including carriage returns, when the user enters a value and presses return.
3. What does fav_num.to_i do?
The method, to_i, converts fav_num's string to an integer.
Exercise #3
In your prework gist, answer the following questions:
1. What does animals.length return?
4
2. What does animals[0] return?
dog
3. What does animals.empty? return?
false
4. What are two different ruby commands that add to the animals?
push and <<
Example:
2.5.0 :007 > animals.push("bird")
=> ["dog", "cat", "penguin", "armadillo", "bird"]
2.5.0 :008 > animals << "crocodile"
=> ["dog", "cat", "penguin", "armadillo", "bird", "crocodile"]
Use insert to multiple values at one time.
5. What ruby command is used to remove the last element from the array?
pop
Example:
2.5.0 :009 > animals.pop
=> "crocodile"
2.5.0 :010 > animals
=> ["dog", "cat", "penguin", "armadillo", "bird"]
2.5.0 :011 >