General Ruby V
1.
What is the result of `puts "hello" * 3` in Ruby?
3hello
hellohellohello
hello3
error
2.
Which method is used to convert a string to an array of characters in Ruby?
split
to_array
chars
convert
3.
What does the `each_with_index` method do on an array in Ruby?
Iterates over each element with its index
Iterates over each element in reverse order
Iterates over every other element
Iterates over each element twice
4.
How do you define a method in Ruby?
define method_name
method method_name
function method_name
def method_name
5.
What is the purpose of the `__dir__` method in Ruby?
Returns the absolute path of the current file's directory
Returns the current working directory
Returns the directory of the parent file
Returns the home directory
6.
What is the output of `puts 10 / 3` in Ruby?
3.33333
3.0
3
Error
7.
In Ruby, what is the purpose of the `+=` operator?
Decrements the variable by a specified value
Increments the variable by a specified value
Multiplies the variable by a specified value
Divides the variable by a specified value
8.
In Ruby, what is the purpose of the `until` keyword?
Executes a block of code while a condition is true
Executes a block of code until a condition becomes true
Executes a block of code for a specified number of times
Ends the program
9.
What is the purpose of the `module_function` method in Ruby?
Makes all methods of a module accessible as module functions
Defines a new module
Excludes methods from a module
Makes all methods of a module private
10.
What is the purpose of the `super` keyword in Ruby?
Calls the method of the same name in the parent class
Stops the execution of the program
Skips the current iteration of a loop
Creates a new instance of a class
11.
What is the result of `"hello".upcase` in Ruby?
h
HELLO
Hello
hello
12.
In Ruby, what is the purpose of the `yield` keyword in a method?
Passes control to a block associated with the method
Returns a value from the method
Raises an exception
Declares a local variable
13.
In Ruby, what is a block?
A section of code enclosed in `do...end`
A data type
An error message
A method call
14.
What is the purpose of the `||=` operator in Ruby?
Performs a logical OR operation between two variables
Assigns a value to a variable regardless of its current value
Compares two variables
Assigns a value to a variable only if the variable is `nil`
15.
How do you convert a number to a string in Ruby?
number.to_s
str(number)
convert(number)
stringify(number)
16.
What is the purpose of the `private` keyword in Ruby?
Defines methods that can only be accessed from the same module
Defines methods that can be accessed from anywhere
Defines methods that can only be accessed within the class hierarchy
Defines methods that can only be accessed within the same class
17.
In Ruby, what is the purpose of the `unless` keyword?
Executes code if a condition is false
Executes code if a condition is true
Ends the program
Skips the current iteration of a loop
18.
How do you define a class variable in Ruby?
@@variable_name
@variable_name
variable_name
Class.variable_name
19.
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
20.
How do you check if a key exists in a hash in Ruby?
key_exists?
exists?
include?
key?