This set of Ruby Programming Multiple Choice Questions & Answers (MCQs) focuses on “Data Types and Variables”.
1. Which of the following datatypes are valid in Ruby?
a) Numbers
b) Boolean
c) String
d) All of the mentioned
View Answer
Explanation: Ruby supports all the three (numbers,strings,boolean) data types.
2. What will any variable evaluate to if it is of Boolean data type?
a) True
b) Nil
c) False
d) Either True or False
View Answer
Explanation: Boolean data types will give the value either as True or False depending on the condition.
3. 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
View Answer
Explanation: Quotation marks are used only with strings.
4. Ruby is a case-sensitive language.
a) True
b) False
View Answer
Explanation: Ruby differentiates between small and capital letters and their meaning.
5. What is the size of an integer data type in ruby?
a) -230 to 230
b) -230 to 2(30-1)
c) -229 to 230
d) -260 to 261
View Answer
Explanation: Integer ranges from -230 to 229 and lies in object of class Fixnum.
6. Ruby can deal with both numbers and floating point values.
a) True
b) False
View Answer
Explanation: We can assingn a integer and a floating point value to a variable.
7. What is the output of the given code?
boolean_1 = 77<78 puts(boolean_1)
a) Nil
b) True
c) False
d) Error
View Answer
Explanation: As 77 is less than 78 hence the boolean value will be printed as true.
Output: True
8. Objects of which class does the integer from the range -2^30 to 2^(30-1) belong to?
a) Bignum
b) Octal
c) Fixnum
d) Binary
View Answer
Explanation: Integer within this range are objects of the class fixnum.
9. What does the notataion \b stands for?
a) Escape
b) Space
c) Backspace
d) Newline
View Answer
Explanation: This notataion is used for backspace.
10. What is the sequence of ruby strings?
a) 16-bit bytes
b) 8-bit bytes
c) 10-bit bytes
d) None of the mentioned
View Answer
Explanation: They are simply the sequence of 8-bit bytes.
11. What is the output of the given code?
my_string=Ruby puts(my_string)
a) Ruby
b) Nil
c) Error
d) None of the mentioned
View Answer
Explanation: Ruby should be written in double quotes inorder to indicate a string.
Output: Error
12. Which of the following is not a valid datatype?
a) Float
b) Integer
c) Binary
d) Timedate
View Answer
Explanation: datetime is valid datatype but timedate is not a valid datatype.
13. What is the range of octal notation (\nnn)?
a) 0-8
b) 0-7
c) 0-A
d) None of the mentioned
View Answer
Explanation: Octal notation ranges from 0-7.
Sanfoundry Global Education & Learning Series – Ruby Programming.
To practice all areas of Ruby Programming, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Ruby Programming Books
- Apply for Programming Internship
- Practice Programming MCQs
- Check Information Technology Books