General Ruby IX
1.
What is the result of `"ruby".length` in Ruby?
2
5
3
4
2.
How do you define a hash in Ruby?
hash = {}
hash.new
new Hash()
create_hash{}
3.
In Ruby, what is the purpose of the `uniq` method on an array?
Returns a new array with duplicate elements removed
Sorts the array in ascending order
Reverses the order of the array
Returns the first element of the array
4.
What is the result of `"hello".upcase` in Ruby?
HELLO
h
Hello
hello
5.
In Ruby, what is the purpose of the `times` method on an integer?
Raises the integer to a specified power
Returns a new array with repeated elements
Multiplies the integer by a specified value
Executes a block of code a specified number of times
6.
In Ruby, what is the purpose of the `delete_if` method on a hash?
Deletes the last key-value pair
Deletes a specific key-value pair
Deletes key-value pairs that satisfy a condition
Deletes all key-value pairs
7.
How do you convert a string to an integer in Ruby?
to_integer(string)
string.to_i
convert_to_integer(string)
integerize(string)
8.
How do you check if a key exists in a hash in Ruby?
hash.key?('key')
key_exists?(hash)
exists?(hash, 'key')
hash.include?('key')
9.
In Ruby, what is the purpose of the `pop` method on an array?
Removes and returns the last element of the array
Adds an element to the end of the array
Sorts the array in ascending order
Reverses the order of the array
10.
What does the `+=` operator do in Ruby?
Increments the variable by a specified value
Decrements the variable by a specified value
Adds a value to the variable
Subtracts a value from the variable
11.
In Ruby, what is the purpose of the `flatten` method on an array?
Returns a new array that is a one-dimensional flattening of the original array
Sorts the array in ascending order
Reverses the order of the array
Returns the first element of the array
12.
What is the result of `puts [1, 2, 3, 4].sample` in Ruby?
1, 2, 3, or 4
Random element from the array
Error
An array containing one element
13.
What is the purpose of the `module` keyword in Ruby?
Defines a class
Defines a module
Defines a method
Creates an instance of a class
14.
What is the result of `puts (1..5).to_a.shuffle` in Ruby?
5, 4, 3, 2, 1
1, 2, 3, 4, 5
Random order of numbers from 1 to 5
Error
15.
What is the output of `"ruby".chars.shuffle.join` in Ruby?
Error
ruby
r
Random permutation of the characters in the string
16.
What is the result of `puts 2**3` in Ruby?
8
6
2
Error
17.
In Ruby, what is the purpose of the `each` method?
Sorts the elements in a collection in ascending order
Iterates over each element in a collection and applies a block of code
Returns the sum of all elements in a collection
Filters out elements in a collection based on a condition
18.
How do you define a constant in Ruby?
By using symbols
By using all lowercase letters
By using a combination of uppercase and lowercase letters
By using all uppercase letters
19.
In Ruby, what is the purpose of the `map` method on an array?
Removes the last element from an array
Applies a block to each element and returns a new array with the results
Sorts the array in ascending order
Combines all elements into a single value
20.
In Ruby, what does the `!` (bang) in a method name often indicate?
The end of the method
A safe or non-destructive version of the method
A dangerous or destructive version of the method
A block for the method