Olete.in
Articles
Mock Tests
🧪 Ruby on Rails MCQ Quiz Hub
Ruby MCQ Questions
Choose a topic to test your knowledge and improve your Ruby on Rails skills
1. Ruby is ?
procedural language
scripting language
Markup language
Stylesheet language
2. Ruby is designed by?
Yukihiro Matsumoto
Guido van Rossum
Tim Berners-Lee
Brendan Eich
3. Ruby was created in?
1992
1993
1994
1995
4. Which of the following statement is not a feature of ruby?
Ruby is interpreted programming language.
Ruby can be used to write Common Gateway Interface (CGI) scripts.
Ruby can be embedded into Hypertext Markup Language (HTML).
Ruby can not be connected to Database.
5. When Whitespace characters such as spaces and tabs can not ignored in Ruby code?
While using strings
While using integer
while using float value
All of the above
6. Reserved word can not be used as?
constant
variable names
Both A and B
None of the above
7. Which character is used to give comment in ruby?
!
@
#
$
8. Global variables in ruby begin with?
@
#
$
&
9. Default value of global variable is?
-1
nil
1
infinite
10. Local variables in ruby begin with?
@ B. C.D.
_
*
#
11. Which of the following Ruby Pseudo-Variables is used for The receiver object of the current method?
self B. C. D.
current
nil
_FILE_
12. Which of the following Ruby Pseudo Variables is used to return current line number in the source file?
_FILE_
_CURRENT_
_LINE_
None of the above
13. Which notation is used for Octal notation?
s
xnn
n
14. Which of the following datatypes are valid in Ruby?
Numbers
String
Boolean
All of the above
15. What is the sequence of ruby strings?
16-bit bytes
8-bit bytes
4-bit bytes
None of the above
16. single-quoted strings don`t allow ?
substitution
backslash notation
single-quoted strings allow substitution and backslash notation.
single-quoted strings don`t allow substitution and allow backslash notation.
17. Objects of which class does the integer from the range -2^60 to 2^(60-1) belong to?
Octal
Bignum
Fixnum
Binary
18. Instance variables in ruby begin with?
@
#
$
&
19. Class variables in ruby begin with?
@
#
double @
##
20. Default value of class variables is?
nil
infinite
-1
error
21. Constants in ruby begin with ?
Lowercase
!
!
Uppercase
22. Which of the following Ruby Pseudo Variables is used to return the name of the current source file?
_FILE_
_CURRENT_
_LINE_
None of the above
23. Why notation is used in Ruby?
Formfeed
Escape
Carriage return
Bell
24. 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 above
25. What is the output of the given code? my_string=Ruby puts(my_string)
Ruby
Nil
Error
my_string
26. Which type of number(0b1011 ) is ?
Octa
Hexadecimal
Binary
Decimal
27. Which of the following is not type of operator in ruby?
Arithmetic Operators
Comparison Operators
Similar operator
Parallel Assignment
28. eql? Operator is used for?
Used to test equality within a when clause of a case statement.
if the receiver and argument have both the same type and equal values.
if the receiver and argument have the same object id.
All of the above
29. Which of the following is not a type of Bitwise Operators?
<<
^
~
None of the above
30. In range operator ... is used for ?
Creates a range from start point to end point inclusive.
Creates a range from start point to end point exclusive.
Creates a range from start point inclusive to end point exclusive.
Creates a range from start point exclusive to end point inclusive
31. Among the following which operator has highest Precedence?
::
.
[]
**
32. What will be the output of the given code? boolean_var = 15 < 16 && 15 < 15 puts boolean_var
TRUE
FALSE
Type Error
Syntax Error
33. What will be the output of the given code? num=4>>2 puts num
-2
0
2
1
34. What will be the output of the given code? boolean_var = 3**2 != 2**3 || true puts boolean_var
TRUE
FALSE
1
0
35. What will be the output of the given code? boolean_var = !(100 / 10 === 10) puts boolean_var
TRUE
FALSE
Type Error
Syntax Error
36. What will the following expression evaluate to? true || false
TRUE
FALSE
Syntax Error
None of the above
37. Which operator is used to find exponent in ruby?
*
**
^
%
38. equal? Operator is used for?
Used to test equality within a when clause of a case statement.
if the receiver and argument have both the same type and equal values.
if the receiver and argument have the same object id.
All of the above
39. Guess the operator : If Condition is true ? Then value X : Otherwise value Y?
Range Operators
Ternary Operator
Parallel Operator
Arithmetic operator
40. Which operator is used to check variable and method are defined or not?
define
define?
defined?
defined
41. Among the following which operator has lowest Precedence?
.
^
...
&gt;&gt;
42. What will be the output of the given code? num=4<<2 puts num
4
8
16
32
43. What will be the output of the given code? num=(10<11)||(11===11)? (11===11.0): 0 puts num
TRUE
FALSE
1
0
44. What will be the output of the given code? boolean_var = false || -20 > -18 puts boolean_var
TRUE
FALSE
Type Error
Syntax Error
45. What will be the output of the given code? boolean_var = !true || (true || 36 != 6**2) puts boolean_var
TRUE
FALSE
Error
None of the above
46. What will the following expression evaluate to? !true && !false
True
False
Syntax Error
None of These
47. Which of the following is not a type of loop in ruby?
For Loop
Foreach Loop
Until Loop
While Loop
48. What is true about while loop?
Executes code while conditional is true
In while loop increment is not required
Executes code while conditional is false
None of the above
49. Which statement is used to Jumps to the next iteration of the most internal loop?
break
next C. D.
redo
retry
50. Which statement is used to restarts the invocation of the iterator call?
break
next
redo
retry
51. What does end represent?
keyword represents the ending of loop
keyword represents the start of loop
keyword represents the start and ending of loop
keyword represents the infinite loop
52. What will be the output of the given code? for num in 1...5 puts num end
1 2 3 4
1 2 3 4 5
0 1 2 3 4
0 1 2 3 4 5
53. What will be the output of the given code? for num in 1...4 puts num*num end
0 1 4 9.
1 4 9 16
0 1 2 3
1 2 3
54. What will be the output of the given code? for i in 1..5 && j in 5..10 puts i+j end
6 8 10 12 14 16
Syntax Error
6 8 10 12 14
Type Error
55. What will be the output of the given code? counter = true while counter !=false puts counter end
TRUE
FALSE
Syntax Error
Infinite Loop
56. What will be the output of the given code? a=1 b=1 while a&&b puts a+b end
2
2 2 2 2 2
Infinite Loop
Syntax Error
57. What is true about Until loop?
Executes code while conditional is true
In until loop increment is not required
Executes code while conditional is false
None of These
58. What is the use of break statement?
Terminates the most External loop.
Terminates all loop
Terminates the program
Terminates the most internal loop.
59. Which statement is used to Restarts this iteration of the most internal loop, without checking loop condition?
break
next
redo
retry
60. What does the 1..5 indicate?
Exclusive range
Both inclusive and exclusive range
Inclusive range
None of the above
61. Which of the following is Exit Controlled loop?
do..while
For
Until
While
62. What will be the output of the given code? for i in 1...3 for j in 1..3 puts j end end
1 2 1 2
0 1 2 0 1 2
1 2 3 1 2 3
1 2 3 1 2
63. What will be the output of the given code? i=1 for i in 6..10 puts i**2 end
36 49 64 81
49 64 81 100
49 64 81
36 49 64 81 100
64. What will be the output of the given code? counter = 1 while counter < 5 puts counter counter = counter + 1 end
Prints the number from 1 to 4
Prints the number from 1 to 5
Prints the number from 2 to 5
Prints the number from 2 to 4
65. What will be the output of the given code? while a&&b puts a end
TRUE
FALSE
Syntax Error
Name Error
66. What will be the output of the given code? i = 4 while i > 0 do print i i -= 1 end
321
3210
4321
43210
Submit