General Ruby VII
1.
What is the result of `"ruby" * 3` in Ruby?
Error
3ruby
rubyruby
rubyrubyruby
2.
In Ruby, what is the purpose of the `<<` operator on an array?
Prepends an element to the beginning of the array
Appends an element to the end of the array
Combines two arrays
Removes the last element from the array
3.
What is the result of `"ruby".upcase` in Ruby?
RUBY
r
Ruby
ruby
4.
What is the purpose of the `<<` operator on a string in Ruby?
Appends another string to the end of the original string
Prepends another string to the beginning of the original string
Concatenates two strings
Removes the last character from the string
5.
In Ruby, what is the purpose of the `uniq` method on an array?
Returns the first element of the array
Sorts the array in ascending order
Reverses the order of the array
Returns a new array with duplicate elements removed
6.
In Ruby, what does the `!` (bang) in a method name often indicate?
A dangerous or destructive version of the method
A safe or non-destructive version of the method
The end of the method
A block for the method
7.
In Ruby, how do you check if an array is empty?
array.empty?
is_empty(array)
check_empty(array)
empty?(array)
8.
What is the purpose of the `each` method in Ruby?
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
9.
How do you define a constant in Ruby?
By using a combination of uppercase and lowercase letters
By using all lowercase letters
By using all uppercase letters
By using symbols
10.
What is the output of `puts (1..3).to_a.reverse` in Ruby?
3, 2, 2001
1, 2, 2003
Error
An array containing numbers from 1 to 3 in reverse order
11.
What does the `compact!` method do on an array in Ruby?
Sorts the array in ascending order
Returns a new array with duplicate elements removed
Modifies the array by removing `nil` elements
Reverses the order of the array
12.
How do you convert a string to an integer in Ruby?
to_integer(string)
string.to_i
convert_to_integer(string)
integerize(string)
13.
In Ruby, what is the purpose of the `rand` method?
Generates a random boolean value
Generates a random integer
Generates a random string
Generates a random floating-point number between 0 and 1
14.
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')
15.
In Ruby, what is the purpose of the `yield` keyword in a method?
Declares a local variable
Returns a value from the method
Raises an exception
Passes control to a block associated with the method
16.
What does the `select!` method do on an array in Ruby?
Reverses the order of the array
Returns a new array with elements that satisfy a condition
Sorts the array in ascending order
Modifies the array by removing elements that don't satisfy a condition
17.
How do you define a method with optional parameters in Ruby?
def method_name(param1 = default_value, param2 = default_value)
def method_name(param1, param2)
def method_name(param1 = default_value, param2)
def method_name(param1, param2 = default_value)
18.
In Ruby, what is the purpose of the `module` keyword?
Defines a module
Defines a class
Defines a method
Creates an instance of a class
19.
How do you check if an object is of a specific class in Ruby?
check_class(object, Class)
is_class?(object)
object.is_a?(Class)
object.instance_of?(Class)
20.
What is the purpose of the `flatten!` method on an array in Ruby?
Reverses the order of the array
Returns a new array with repeated elements
Sorts the array in ascending order
Modifies the array by removing nested arrays