Loading...
QUIZ

Certification Test

 
Que No. 1 ) How do you define a method with optional parameters in Ruby?

A.) def my_method(x = 10)
B.) def my_method(x, y = 10)
C.) def my_method(x?, y)
D.) def my_method(x, y?)


Que No. 2 ) What is the purpose of the attr_accessor method in Ruby?

A.) To create a new class
B.) To define a loop
C.) To generate getter and setter methods for class attributes
D.) To declare a variable


Que No. 3 ) How do you define an instance variable in Ruby?

A.) @my_var = value
B.) var my_var = value
C.) $my_var = value
D.) @@my_var = value


Que No. 4 ) What is the purpose of the yield keyword in a Ruby block?

A.) To exit the block
B.) To create a loop
C.) To pass control back to the caller and execute the caller's block
D.) To declare a variable


Que No. 5 ) How do you define a class method in Ruby using the self keyword?

A.) def MyClass.my_method
B.) def my_method.self
C.) def self.my_method
D.) self.my_method


Que No. 6 ) What is the Ruby syntax for defining a range from 1 to 10 (inclusive)?

A.) 1..10
B.) 1-10
C.) [1, 10]
D.) (1...10)


Que No. 7 ) What is the purpose of the case statement in Ruby?

A.) To define a function
B.) To execute code based on a condition
C.) To create an object
D.) To declare a variable


Que No. 8 ) How do you define a private method in a Ruby class?

A.) private def my_method
B.) def private my_method
C.) def my_method.private
D.) private: my_method


Que No. 9 ) What is the purpose of the next statement in a Ruby loop?

A.) To exit the loop
B.) To restart the loop
C.) To skip to the next iteration of the loop
D.) To define a function


Que No. 10 ) What is the Ruby syntax for defining a hash (dictionary) with key-value pairs?

A.) {1: "one", 2: "two"}
B.) {1 => "one", 2 => "two"}
C.) [1: "one", 2: "two"]
D.) [1 => "one", 2 => "two"]