Olete.in
Articles
Mock Tests
🧪 Ruby MCQ Quiz Hub
Ruby Multiple Choice Questions Set 1
Choose a topic to test your knowledge and improve your Ruby skills
1. Which of the following is supported by Ruby?
Multiple Programming Paradigms
Dynamic Type System
Automatic Memory Management
All of the Mentioned
2. Which of the following features does the 2.0 version of ruby supports?
Method keyword arguments
New literals
Security fixes
All of the mentioned
3. Which of the following languages syntax matches with the Ruby’s syntax?
Perl
PHP
Java
Jquery
4. What is the extension used for saving the ruby file?
ruby extension
.rb extension
rrb extension
None of the mentioned
5. Which of the following are valid floating point literal?
.5
2
0.5
None of the mentioned
6. Which of the following datatypes are valid in Ruby?
Numbers
Boolean
String
All of the mentioned
7. What will any variable evaluate to if it is of Boolean data type?
True
Nil
False
Either True or False
8. Why can not we use quotation marks (‘ or “) with boolean?
It indicates that we are talking about a string
It indicates that we are assining a value
It indicates that that we are replacing boolean data type with string data type
None of the mentioned
9. What is the size of an integer data type in ruby?
-230 to 230
-230 to 2(30-1)
-229 to 230
-260 to 261
10. What is the output of the given code? boolean_1 = 77<78 puts(boolean_1)
Nil
True
False
Error
11. Objects of which class does the integer from the range -2^30 to 2^(30-1) belong to?
Bignum
Octal
Fixnum
Binary
12. What does the notataion stands for?
Escape
Space
Backspace
Newline
13. What is the output of the given code? my_string=Ruby puts(my_string)
Ruby
Nil
Error
None of the mentioned
14. Which of the following is not a valid datatype?
Float
Integer
Binary
Timedate
15. What is the range of octal notation ( nn)?
0-8
0-7
0-A
None of the mentioned
16. Which of the following is not a valid library function?
Puts
Print
Gets
Get
17. Why is the library function ‘puts’used for?
Prints whatever is given and print it to the screen
Prints whatever is given and insert a new(blank) line
Gets input from the user
None of the mentioned
18. For getting an input from the user which method is used?
get
gets.chomp
get-s
chomp
19. What is the output of given code? puts "what is your first name?" name=gets.chomp puts "what is your surname?" surname=gets.chomp
Error in compilation
What is your first name? xyz(enter any name) What is your surname? wtu(enter your surname)
Name=xyz
None of the mentioned
20. Which sequence can be used to substitute the value of any ruby expression in a string?
#(expr)
#{expr}
#expr
None of the mentioned
21. Why is gets not preferred instead of gets.chomp?
Gets add an extra new line while chomp removes it
Gets remove an extra new line
Chomp erases the value stored in the variable
All of the mentioned
22. 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} "
Error in compilation
Give your address
What’s your address? Chennai Tamilnadu 600048 Iam from Chennai city, Tamilnadu state, pincode: 600048
None of the mentioned
23. What is the output of the the given code? puts "My name is #{Name}"
Error in compilation
Name variable not defined earlier
My name is #{Name}
Undefined Error
24. 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"
Error, no output
Ruby is an oop language It is very efficient langauge undefined local variable
Ruby is an oop language It is very efficient langauge #{expr} is used on rails platform
None of the mentioned
25. What is the output of the given code? Ans=Ruby puts "#[Ans] is an oop language"
Error, no output
Ruby is an oop language
Warning:already initialized constant Ans
None of the mentioned
26. Which of the following is not a valid library function?
Puts
Print
Gets
Get
27. Which of the following is the valid string method?
The .length method
The .upcase method
The .downcase method
The .irreverse method
28. What is the output of the following? "Iam learning ruby language".length
26
23
20
18
29. What will be the output of the following? "Eric".irreverse
Eric
cirE
undefined method
None of the mentioned
30. What does the .upcase method do?
Convert the string to uppercase
Convert only lowercase string to uppercase and vice-versa
Convert the string to lowercase
None o the mentioned
31. What will be the output of the following? "Ruby".reverse.upcase
RUBY
ybuR
YBUR
YBUr
32. What will be the output of the given code? "I'am learning Ruby Language".length.reverse.upcase
27
egaugnal ybuR gninreal ma’I
ERAUGNAL YBUR GNINREAL MA’I
Undefined method `reverse’ for 27:Fixnum
33. What will we the output of the given code? "I'am Learning RUBY Language".downcase
iam learning ruby language
i’AM lEARNING ruby lANGUAGE
i’am learning ruby language
None of the mentioned
34. What is the output of given code? string="I'am Learning RUBY Language".downcase string.upcase
Undefined method
“I’AM LEARNING RUBY LANGUAGE
I’am Learning RUBY Language
None of the mentioned
35. What will be the output of the given code? "Come let's learn.reverse Ruby.length language".upcase
nreal s’tel emoC 4 LANGUAGE
Undefined error
COME LET’S LEARN.REVERSE RUBY.LENGTH LANGUAGE
All of the above
36. What will we the output of the given code? I'am Learning RUBY Language.downcase
iam learning ruby language
i’AM lEARNING ruby lANGUAGE
i’am learning ruby language”
unterminated string meets end of file
37. What is the use of .capitalize method?
It capitalizes the entire string
It capitalize on the first letter of the string
It capitalize the strings which are in small case
All of the mentioned
38. What is the role of ! at the end of the capitalize method?
It is the syntax for using capitalize method
It modifies the value stored in the variable
It indicates the termination of string
None of the mentioned
39. 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}"
Amil Jones
What’s your first name? amil What’s your last name? jones My name is Amil Jones
My name is Amil Jones
None of the mentioned
40. 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}"
Amil Jones
What’s your first name? amil What’s your last name? jones My name is Amil Jones
What’s your first name? amil What’s your last name? jones My name is Amil jones
None of the mentioned
41. 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}"
amil jones
What’s your first name? amil My name is amil
My name is lima
My name is limA
42. 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}"
mil jones
What’s your first name? amil My name is Amil
My name is lima
My name is limA
43. 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}"
amil jones
What’s your first name? amil My name is Amil
What’s your first name? amil My name is limA
My name is limA
44. What do we mean by expression substitution?
Embedding the value of Ruby expression into a string using #{ }
Substituting string functions
Storing string value
None of the mentioned
45. 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 }."
12,48,40
Syntax error
The value of x is 12. The sum of x and y is 48. The average was 40.
None of the mentioned
46. What does %{Learn ruby language} represents? a) “ b) “%{Learn Ruby language}” c) ” d) None of the mentioned
Learn Ruby language”
“%{Learn Ruby language}”
Learn Ruby language ”
None of the mentioned
47. What does %Q{ Learn ruby language } represents? a) ”
Learn Ruby language ”
“%{ Learn Ruby language }”
Learn Ruby language
None of the mentioned
48. What does %x!ls! represents?
Same as back tick command output `ls`
Same as ‘x’
Same as “xls”
None of the mentioned
49. Why do we use comments?
For later use to understand the working of the program
It is an efficient way of programming
It makes easy for the third person to understand
All of the Mentioned
50. How to comment multiple lines in ruby? a)
Using multiline comments
No option to comment
Using single line comment
All of the mentioned
51. How to comment multiple lines in ruby?
Using multiline comments
Using single line comments
No option to comment
All of the mentioned
52. How to comment a single line?
Using #
Using begin and end
Using //
None of the mentioned
53. What is the output of the given code? “Ruby”.length #to find the length of given string
4 to find the length of given string
4
To find the length of given string
Ruby
54. Why do we use =begin and =end?
To mark the start and end of multiline comment
To comment multiple lines
To avoid the use of # again and again
All of the mentioned
55. What is the output of the given code? "Ruby Language".length =begin calculate length =end
13
13 calculate length
12
None of the mentioned
56. What is the output of the given code? "Ruby Language".length = begin calculate length = end
13
12
Error
None of the mentioned
57. If expression. The expression can be of which type?
True
Any number
Any string
All of the mentioned
58. What is the output of the following? if 1<2 print "one is less than two" end
One is less than two
Syntax error
1&lt;2
None of the mentioned
59. What is the output of the code? if 11<2 print "Eleven is less than two" end print "11 is greater"
11 is greater
Eleven is less than two
Eleven is less than two 11 is greater
None of the mentioned
60. What is the output of the given code? if 11>2 puts "Eleven is greater than two" end print "You'r right"
Eleven is greater than two
You’r right
Eleven is greater than two You’r right
None of the mentioned
61. 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)
True false true false
True True True False
False False True True
None of the mentioned
62. 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
a and b are same
Not same
a==b
None of the mentioned
63. 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
a greater than b
Not greater
Syntax error
None of the mentioned
64. Which of the following are used for comparison?
Equal to
Not equal to
Less than or greater than
All of the mentioned
65. What is the output of the given code? if(a==10 && b=9) print "true" else print "false" end
True
False
Error
None of the mentioned
66. What is the output of the given code? counter=1 if counter<=5 puts (counter) counter=counter+1
Syntax error
1 2
1
None of the mentioned
67. Which of the following is a valid boolean operator?
and(&amp;&amp;)
or(||)
not(!)
All of the mentioned
68. What will the following expression evaluate to? true && false
True
False
Error
None of the mentioned
69. What will be the output of the given code?boolean_1 = 77 < 78 && 77 < 77 puts boolean_1
True
False
Error
None of the mentioned
70. What will the following expression evaluate to? true || false mentioned
True
False
Error
None of the mentioned
71. What will the following expression evaluate to? (true && false) || (!true)
True
False
Error
None of the mentioned
72. What will the following expression evaluate to? !true && !false
True
False
Error
None of the mentioned
73. What will be the output of the given code? boolean_1 = (3 < 4 || false) && (false || true) puts boolean_1
True
False
Error
None of the mentioned
74. What will be the output of the given code? boolean_1 = !(3 < 4 || false) && (false || true) puts boolean_1
True
False
Error
None of the mentioned
75. What will be the output of the given code? boolean_1 = false || -10 > -9 puts boolean_1
True
False
Error
None of the mentioned
76. What will be the output of the given code? boolean_1 = !(700 / 10 == 70) puts boolean_1
True
False
Error
None of the mentioned
77. What will be the output of the given code? boolean_1 = !true puts boolean_1 boolean_2 = !true && !true puts boolean_2
True True
False False
True False
None of the mentioned
78. What will be the output of the given code? boolean_2 = !true && (!true || 100 != 5**2) puts boolean_2
True
False
Error
None of the mentioned
79. Which of the following is a valid assignment operator?
+=
-=
*=
All of the mentioned
80. What does the **= assignment operator do?
Multiplies the value twice
It is used as exponent like 2**3=8
It is the multiplication operator.
None of the mentioned
81. What is the output of the given code? counter = 1 while counter < 11 puts counter counter+=1 end
1 2 3 4 5
1…10
1..10
None of the mentioned
82. What is the output of the given code? counter = 100 while counter > 0 puts counter counter/=5 end
100 20 4
100 20 5
100..5
None of the mentioned
83. What is the output of the given code? counter = 100 while counter > 0 puts counter counter-=25 end
100 75 50 25
100 25 5
100..5
None of the mentioned
84. What is the output of the given code? counter = -50 while counter <0 puts counter counter+=10 end
100 75 50 25
-50 -40 -30 -20 -10
100..5
None of the mentioned
85. What is the output of the given code? a = 22.5 while a >11.5 puts a a-=3.5 end
22.5 19.0 15.5 12.0
22.5 11.5
100..5
None of the mentioned
86. 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
10 20
15 19 23
15 16 17 18 19 20
None of the mentioned
87. 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
10 20
15 19 23
50 84 126
None of the mentioned
88. 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
10 20
15 19 23
-5 -5 -5
None of the mentioned
89. 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
0 20
50 84 126 176 234
-5 -5 -5
None of the mentioned
90. 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
10 20
50 84 126 176 234
-5 -5 -5
None of the mentioned
Submit