Study Code Flashcards
to_s
convert object to a string
.reverse
reverses a string only
.length
counts characters in a string only
to_i
converts object to an integer
to_a
converts object to an array [an array is a list in these types of brackets separated by commas]
.max
a method to find the highest number in an array.
What is being done here?
ticket = [12, 47, 35]
A variable is being created named “ticket”, which now defines the array of integers [12,47,35]. This new variable can now have methods called on it such as ticket.max to get the highest number in the array.
.sort
sorts an array of integers from the lowest to the highest.
.join
converts an array to a single string.
What is the ! for in the below code
.sort!
The exclamation means the the array in which the sort method is being called on will permanently alter the array when completed.
.clear
clears the called upon variable
example: > variable = “abcde”
variable. clear returns :> “”
.downcase
converts a string to ALL lowercase “A” to “Z” characters only.
.empty?
Asks if a string is empty or not.
Example:> “hello”.empty? returns false
““.empty? returns true
What will the following code result in?
Variable.rstrip.lstrip
rstrip and lstrip will remove any white spaces from a string (right, or left sides). If no spaces are removed, will result in nil.
What will the following code result in?
“ Now’s the time”.split
The .split method splits each word into a separate string using the empty white spaces to determine word beginning and end. Other types of characters can be used to split by defining at the end of the .split method.
What will the following code result in?
books = { }
This action will create an empty hash named “books.” A hash can be considered a dictionary.
If you have a hash named “Books,” what would the following code result in?
books.length
The code would return the amount of book titles in the hash.
Describe the following code in detail.
books[“Jake’s Home Design Review”] = :quite_good.
This is a hash named “books”, which includes a book titled “Jake’s Home Design Review,” which is the KEY of the hash. Then there is a VALUE (noted by the :) which rates the book as quite good.