Loading...
QUIZ

Certification Test

 
Que No. 1 ) Which of the following is not a valid way to create and initialize an array in Ruby?

A.) arr = [1, 2, 3]
B.) arr = Array.new(3) { |i| i + 1 }
C.) arr = [1..3]
D.) arr = [] << 1 << 2 << 3


Que No. 2 ) What is the purpose of the module keyword in Ruby?

A.) To create a class
B.) To define a loop
C.) To group related code into a namespace
D.) To declare a variable


Que No. 3 ) Which of the following is not a valid way to catch exceptions in Ruby?

A.) rescue Exception => e
B.) catch (Exception ex) {}
C.) rescue => e
D.) rescue SomeException => e


Que No. 4 ) How do you define a lambda function in Ruby?

A.) lambda { |x| x * 2 }
B.) def lambda(x) { x * 2 } end
C.) func(x) { x * 2 }
D.) create lambda(x) { x * 2 }


Que No. 5 ) What does the nil value represent in Ruby?

A.) An empty string
B.) A missing or undefined value
C.) The number zero
D.) An error


Que No. 6 ) How do you define a block in Ruby?

A.) block { |x| x * 2 }
B.) def block(x) { x * 2 } end
C.) { |x| x * 2 }
D.) create block(x) { x * 2 }


Que No. 7 ) What is the purpose of the super keyword in Ruby?

A.) To define a loop
B.) To execute code based on a condition
C.) To call a method in the superclass
D.) To declare a variable


Que No. 8 ) Which of the following is not a valid way to iterate through a collection in Ruby?

A.) for item in collection
B.) collection.each do |item|
C.) while condition
D.) until condition


Que No. 9 ) What is the Ruby syntax for defining a class constructor?

A.) constructor MyClass { }
B.) MyClass.new { }
C.) def MyClass.initialize
D.) def initialize


Que No. 10 ) What is the purpose of the include keyword in Ruby?

A.) To define a class
B.) To create an instance of a class
C.) To include a module's methods in a class
D.) To declare a variable