Test your knowledge of Ruby

Test your knowledge of Ruby

Take this quiz to see how well you know the Ruby programming language.

published on October 26, 2023
1/12

Which of the following is a valid way to define a class in Ruby?

Which of the following is a valid way to define a class in Ruby?
class MyClass()
class MyClass end
def MyClass
module MyClass end
2/12

What is the symbol used to denote a line comment in Ruby?

What is the symbol used to denote a line comment in Ruby?
//
/* */
#
--
3/12

Which of the following is a valid way to print 'Hello, World!' in Ruby?

Which of the following is a valid way to print 'Hello, World!' in Ruby?
log 'Hello, World!'
console.print('Hello, World!')
print('Hello, World!')
puts 'Hello, World!'
4/12

What is the result of the expression '3 + 4' in Ruby?

What is the result of the expression '3 + 4' in Ruby?
34
7
3 + 4
Syntax Error
5/12

Which of the following is a correct way to create a new array in Ruby?

Which of the following is a correct way to create a new array in Ruby?
my_array = []
my_array = Array[]
my_array = Array.new()
my_array = array{}
6/12

What does the 'nil' value represent in Ruby?

What does the 'nil' value represent in Ruby?
Zero
Nothing or absence of value
True
NaN
7/12

Which of the following is not a logical operator in Ruby?

Which of the following is not a logical operator in Ruby?
&&
|
!
!=
8/12

What is the correct way to check if a variable 'x' is equal to 5 in Ruby?

What is the correct way to check if a variable 'x' is equal to 5 in Ruby?
x =! 5
x != 5
x = 5
x == 5
9/12

Which method is used to convert a string to uppercase in Ruby?

Which method is used to convert a string to uppercase in Ruby?
lowercase
upcase
uppercase
to_upper
10/12

What is the output of the following code?
x = [1, 2, 3, 4, 5]
puts x[3]

What is the output of the following code?   x = [1, 2, 3, 4, 5]   puts x[3]
5
Syntax Error
[4]
4
11/12

Which method is used to remove the last element from an array in Ruby?

Which method is used to remove the last element from an array in Ruby?
remove_last
remove
delete_last
pop
12/12

What is the output of the following code?
x = 10
y = x > 5 ? 'Yes' : 'No'
puts y

What is the output of the following code?   x = 10   y = x > 5 ? 'Yes' : 'No'   puts y
Yes
No
YesNo
Syntax Error