Ruby Questions and Answers – Data Types and Variables

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

Answer: d
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

Answer: d
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

Answer: a
Explanation: Quotation marks are used only with strings.
advertisement
advertisement

4. Ruby is a case-sensitive language.
a) True
b) False
View Answer

Answer: a
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

Answer: b
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

Answer: a
Explanation: We can assingn a integer and a floating point value to a variable.

7. What is the output of the given code?

advertisement
boolean_1 = 77<78
   puts(boolean_1)

a) Nil
b) True
c) False
d) Error
View Answer

Answer: b
Explanation: As 77 is less than 78 hence the boolean value will be printed as true.

advertisement
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

Answer: c
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

Answer: c
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

Answer: b
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

Answer: c
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

Answer: d
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

Answer: b
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.