πŸ§ͺ Ruby MCQ Quiz Hub

Ruby Multiple Choice Questions Set 1

Choose a topic to test your knowledge and improve your Ruby skills

Which of the following is supported by Ruby?





βœ… Correct Answer: 4

Which of the following features does the 2.0 version of ruby supports?





βœ… Correct Answer: 4

Which of the following languages syntax matches with the Ruby’s syntax?





βœ… Correct Answer: 1

What is the extension used for saving the ruby file?





βœ… Correct Answer: 2

Which of the following are valid floating point literal?





βœ… Correct Answer: 4

Which of the following datatypes are valid in Ruby?





βœ… Correct Answer: 4

What will any variable evaluate to if it is of Boolean data type?





βœ… Correct Answer: 4

Why can not we use quotation marks (β€˜ or β€œ) with boolean?





βœ… Correct Answer: 1

What is the size of an integer data type in ruby?





βœ… Correct Answer: 4

What is the output of the given code? boolean_1 = 77<78 puts(boolean_1)





βœ… Correct Answer: 2

Objects of which class does the integer from the range -2^30 to 2^(30-1) belong to?





βœ… Correct Answer: 3

What does the notataion  stands for?





βœ… Correct Answer: 3

What is the output of the given code? my_string=Ruby puts(my_string)





βœ… Correct Answer: 3

Which of the following is not a valid datatype?





βœ… Correct Answer: 4

What is the range of octal notation ( nn)?





βœ… Correct Answer: 2

Which of the following is not a valid library function?





βœ… Correct Answer: 4

Why is the library function β€˜puts’used for?





βœ… Correct Answer: 2

For getting an input from the user which method is used?





βœ… Correct Answer: 2

What is the output of given code? puts "what is your first name?" name=gets.chomp puts "what is your surname?" surname=gets.chomp





βœ… Correct Answer: 2

Which sequence can be used to substitute the value of any ruby expression in a string?





βœ… Correct Answer: 2

Why is gets not preferred instead of gets.chomp?





βœ… Correct Answer: 1

What is the output of the given code? print "What's your address" city,state,pin=gets.chomp,gets.chomp,gets.chomp puts "Iam from #{city} city, #{state} state, pincode: #{pin} "





βœ… Correct Answer: 3

What is the output of the the given code? puts "My name is #{Name}"





βœ… Correct Answer: 2

What is the output of the given code? Ans=Ruby puts "#{Ans} is an oop language" puts "It is very efficient langauge" puts "#{expr} is used on rails platform"





βœ… Correct Answer: 2

What is the output of the given code? Ans=Ruby puts "#[Ans] is an oop language"





βœ… Correct Answer: 2

Which of the following is not a valid library function?





βœ… Correct Answer: 4

Which of the following is the valid string method?





βœ… Correct Answer: 4

What is the output of the following? "Iam learning ruby language".length





βœ… Correct Answer: 1

What will be the output of the following? "Eric".irreverse





βœ… Correct Answer: 3

What does the .upcase method do?





βœ… Correct Answer: 1

What will be the output of the following? "Ruby".reverse.upcase





βœ… Correct Answer: 3

What will be the output of the given code? "I'am learning Ruby Language".length.reverse.upcase





βœ… Correct Answer: 4

What will we the output of the given code? "I'am Learning RUBY Language".downcase





βœ… Correct Answer: 3

What is the output of given code? string="I'am Learning RUBY Language".downcase string.upcase





βœ… Correct Answer: 2

What will be the output of the given code? "Come let's learn.reverse Ruby.length language".upcase





βœ… Correct Answer: 3

What will we the output of the given code? I'am Learning RUBY Language.downcase





βœ… Correct Answer: 4

What is the use of .capitalize method?





βœ… Correct Answer: 2

What is the role of ! at the end of the capitalize method?





βœ… Correct Answer: 2

What is the output of the code? print "What's your first name?" first_name=gets.chomp a=first_name.capitalize first_name.capitalize! print "What's your last name?" last_name=gets.chomp b=last_name.capitalize last_name.capitalize! puts "My name is #{first_name} #{last_name}"





βœ… Correct Answer: 2

What is the output of the code? print "What's your first name?" first_name=gets.chomp a=first_name.capitalize first_name.capitalize! print "What's your last name?" last_name=gets.chomp b=last_name.capitalize last_name.capitalize puts "My name is #{first_name} #{last_name}"





βœ… Correct Answer: 2

What is the output of the given code? print "what's your first name?" first_name=gets.chomp a=first_name.capitalize "first_name.capitalize!".reverse puts"My name is #{first_name}"





βœ… Correct Answer: 2

What is the output of the given code? print "what's your first name?" first_name=gets.chomp a=first_name.capitalize "a".reverse puts"My name is #{a}"





βœ… Correct Answer: 2

What is the output of the given code? print "What's your first name?" first_name=gets.chomp a=first_name.capitalize a=a.reverse puts"My name is #{a}"





βœ… Correct Answer: 2

What do we mean by expression substitution?





βœ… Correct Answer: 1

What is the output of the given code? x, y, z = 12, 36, 72 puts "The value of x is #{ x }." puts "The sum of x and y is #{ x + y }." puts "The average was #{ (x + y + z)/3 }."





βœ… Correct Answer: 3

What does %{Learn ruby language} represents? a) β€œ b) β€œ%{Learn Ruby language}” c) ” d) None of the mentioned





βœ… Correct Answer: 1

What does %Q{ Learn ruby language } represents? a) ”





βœ… Correct Answer: 1

What does %x!ls! represents?





βœ… Correct Answer: 1

Why do we use comments?





βœ… Correct Answer: 4

How to comment multiple lines in ruby? a)





βœ… Correct Answer: 1

How to comment multiple lines in ruby?





βœ… Correct Answer: 1

How to comment a single line?





βœ… Correct Answer: 1

What is the output of the given code? β€œRuby”.length #to find the length of given string





βœ… Correct Answer: 2

Why do we use =begin and =end?





βœ… Correct Answer: 4

What is the output of the given code? "Ruby Language".length =begin calculate length =end





βœ… Correct Answer: 1

What is the output of the given code? "Ruby Language".length = begin calculate length = end





βœ… Correct Answer: 3

If expression. The expression can be of which type?





βœ… Correct Answer: 4

What is the output of the following? if 1<2 print "one is less than two" end





βœ… Correct Answer: 1

What is the output of the code? if 11<2 print "Eleven is less than two" end print "11 is greater"





βœ… Correct Answer: 1

What is the output of the given code? if 11>2 puts "Eleven is greater than two" end print "You'r right"





βœ… Correct Answer: 3

What is the output of the given code? test_1 = 17 > 16 puts(test_1) test_2 = 21 <= 30 puts(test_2) test_3 = 9 >= 9 puts(test_3) test_4 = -11 > 4 puts(test_4)





βœ… Correct Answer: 2

What is the output of the given code? a="string" b="strings" if(a==b) print ("a and b are same") else print "Not same" end





βœ… Correct Answer: 2

What is the output of the given code? a=10 b=9 if(a>b) print ("a greater than b") else print "Not greater" end





βœ… Correct Answer: 1

Which of the following are used for comparison?





βœ… Correct Answer: 4

What is the output of the given code? if(a==10 && b=9) print "true" else print "false" end





βœ… Correct Answer: 3

What is the output of the given code? counter=1 if counter<=5 puts (counter) counter=counter+1





βœ… Correct Answer: 1

Which of the following is a valid boolean operator?





βœ… Correct Answer: 4

What will the following expression evaluate to? true && false





βœ… Correct Answer: 2

What will be the output of the given code?boolean_1 = 77 < 78 && 77 < 77 puts boolean_1





βœ… Correct Answer: 2

What will the following expression evaluate to? true || false mentioned





βœ… Correct Answer: 1

What will the following expression evaluate to? (true && false) || (!true)





βœ… Correct Answer: 2

What will the following expression evaluate to? !true && !false





βœ… Correct Answer: 2

What will be the output of the given code? boolean_1 = (3 < 4 || false) && (false || true) puts boolean_1





βœ… Correct Answer: 1

What will be the output of the given code? boolean_1 = !(3 < 4 || false) && (false || true) puts boolean_1





βœ… Correct Answer: 2

What will be the output of the given code? boolean_1 = false || -10 > -9 puts boolean_1





βœ… Correct Answer: 1

What will be the output of the given code? boolean_1 = !(700 / 10 == 70) puts boolean_1





βœ… Correct Answer: 2

What will be the output of the given code? boolean_1 = !true puts boolean_1 boolean_2 = !true && !true puts boolean_2





βœ… Correct Answer: 3

What will be the output of the given code? boolean_2 = !true && (!true || 100 != 5**2) puts boolean_2





βœ… Correct Answer: 2

Which of the following is a valid assignment operator?





βœ… Correct Answer: 4

What does the **= assignment operator do?





βœ… Correct Answer: 2

What is the output of the given code? counter = 1 while counter < 11 puts counter counter+=1 end





βœ… Correct Answer: 3

What is the output of the given code? counter = 100 while counter > 0 puts counter counter/=5 end





βœ… Correct Answer: 1

What is the output of the given code? counter = 100 while counter > 0 puts counter counter-=25 end





βœ… Correct Answer: 1

What is the output of the given code? counter = -50 while counter <0 puts counter counter+=10 end





βœ… Correct Answer: 2

What is the output of the given code? a = 22.5 while a >11.5 puts a a-=3.5 end





βœ… Correct Answer: 2

What is the output of the given code? a = 5 b=10 while a <10 && b<20 puts a+b a+=2 b+=2 end





βœ… Correct Answer: 2

What is the output of the given code? a = 5 b=10 while a <10 && b<20 puts a*b a+=2 b+=2 end





βœ… Correct Answer: 3

What is the output of the given code? a= 5 b=10 while a <10 && b<20 puts a-b a+=2 b+=2 end





βœ… Correct Answer: 3

What is the output of the given code? a = 5 b=10 while a <10 || b<20 puts a*b a+=2 b+=2 end





βœ… Correct Answer: 2

What is the output of the given code? a = 5 b=10 while (a <10 || b<20)&&true puts a*b a+=2 b+=2 end





βœ… Correct Answer: 2