Ruby Questions and Answers Part-2

1. What will any variable evaluate to if it is of Boolean data type?
a) True
b) Nil
c) False
d) Either True or False

Answer: d
Explanation: Boolean data types will give the value either as True or False depending on the condition.

2. 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

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

3. Ruby is a case-sensitive language.
a) True
b) False

Answer: a
Explanation: Ruby differentiates between small and capital letters and their meaning.

4. 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

Answer: b
Explanation: Integer ranges from -230 to 229 and lies in object of class Fixnum.

5. Ruby can deal with both numbers and floating point values.
a) True
b) False

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

6. What is the output of the given code?
boolean_1 = 77<78
puts(boolean_1)
a) Nil
b) True
c) False
d) Error

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

7. 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

Answer: c
Explanation: Integer within this range are objects of the class fixnum.

8. What does the notataion \b stands for?
a) Escape
b) Space
c) Backspace
d) Newline

Answer: c
Explanation: This notataion is used for backspace.

9. What is the sequence of ruby strings?
a) 16-bit bytes
b) 8-bit bytes
c) 10-bit bytes
d) None of the mentioned

Answer: b
Explanation: They are simply the sequence of 8-bit bytes.

10. 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

Answer: c
Explanation: Ruby should be written in double quotes inorder to indicate a string.