Home / Programming Questions / Ruby MCQs / Page 16

Ruby MCQs with answers Page - 16

Dear candidates you will find MCQ questions of Ruby here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Share your questions by clicking Add Question

Y

Yatendra Sir • 5.60K Points
Tutor III

Q. What will be output for the following code?

Code:
begin
         
    puts 'This is Before Exception Arise!'
         
       raise 'Exception Created!'
   
    puts 'After Exception' 
end
(A) This is Before Exception Arise! After Exception!
(B) Exception Created! After Exception!
(C) This is Before Exception Arise! Exception Created!
(D) This is Before Exception Arise! Exception Created! After exception

Y

Yatendra Sir • 5.60K Points
Tutor III

Q. Which statement will execute at the end of the code, whether the exception raise or not?

(A) retry
(B) raise
(C) ensure
(D) else

Y

Yatendra Sir • 5.60K Points
Tutor III

Q. What will be output for the following code?

Code:
begin
         
    raise 'Exception Created!'
   
    puts 'After Exception' 
   
  rescue    
    puts 'Finally Saved!'
    
ensure
   puts 'ensure block execute'
end
(A) ensure block execute
(B) After exception! Finally Saved! ensure block execute
(C) Ecxception Created! Finally Saved! ensure block execute
(D) Finally Saved! ensure block execute

Y

Yatendra Sir • 5.60K Points
Tutor III

Q. Which block only executes when no exception is raised?

(A) retry
(B) raise
(C) ensure
(D) else

Y

Yatendra Sir • 5.60K Points
Tutor III

Q. What will be output for the following code?

Code:
begin
         
    puts 'no Exception raise' 
  
    rescue    
        puts 'Finally Saved!'
  
   else
        puts 'Else block execute because of no exception raise'
       
   ensure
      puts 'ensure block execute'
end
(A) no Exception raise Else block execute because of no exception raise ensure block execute
(B) no Exception raise Else block execute because of no exception raise
(C) Finally Saved! Else block execute because of no exception raise ensure block execute
(D) None of the above

Y

Yatendra Sir • 5.60K Points
Tutor III

Q. What will be output for the following code When input number is ""!""?

Code:
def catch_and_throw(value) 
  
  puts value 
  a = readline.chomp 
  
  throw :value_e if a == ""!""
  return a 
  
end
  
catch :value_e do
  
  number = catch_and_throw(""Enter Number: "") 
end
(A) Error
(B) 0
(C) Nil
(D) Infinite Loop

M

Mr. Dubey • 51.17K Points
Coach

Q. Why is gets not preferred instead of gets.chomp?

(A) Gets add an extra new line while chomp removes it
(B) Gets remove an extra new line
(C) Chomp erases the value stored in the variable
(D) All of the mentioned

M

Mr. Dubey • 51.17K Points
Coach

Q. Why can not we use quotation marks (' or ") with boolean?

(A) It indicates that we are talking about a string
(B) It indicates that we are assining a value
(C) It indicates that that we are replacing boolean data type with string data type
(D) None of the mentioned

Login

Forgot username? click here

Forgot password? Click here

Don't have account? Register here.