Ruby Programming Questions and Answers – Introduction to Hashes

This set of Ruby Programming Interview Questions and Answers for Experienced people focuses on “Introduction to Hashes”.
1. It is possible to make array of booleans.
a) True
b) False
View Answer

Answer: a
Explanation: Arrays of strings, numbers, booleans can be made.

2. What is the output of the given code?

string_array = ["a","e","i","o","u"]
print string_array

a) [“a”,”e”,”i”,”o”,”u”].
b) Error
c) Vowels
d) None of the mentioned
View Answer

Answer: a
Explanation: The array is a string array.

Output:
["a","e","i","o","u"]

3. What is the output of the given code?

advertisement
advertisement
string_array = ["a","e","i","o","u"]
print string_array[3]

a) [“a”,”e”,”i”,”o”,”u”].
b) Error
c) o
d) None of the mentioned
View Answer

Answer: c
Explanation: The array is a string array and the index is 3 so ‘o’ will be the output.

Output:
o

4. What is the output of the given code?

advertisement
string_array = ["a","e","i","o","u"]
boolean_array = ["True","False"]
puts string_array[3]
puts boolean_array

a) [“a”,”e”,”i”,”o”,”u”].
b) Error
c)

advertisement
o
  True
  False

d) None of the mentioned
View Answer

Answer: c
Explanation: The array is a string array and the index is 3 so ‘o’ will be the output and then the boolean_array will get printed.

Output:
o
True
False

5. What is the output of the given code?

string_array = ["a","e","i","o","u"]
boolean_array = ["True","False"]
puts string_array[3]
puts boolean_array[1]

a) [“a”,”e”,”i”,”o”,”u”].
b) Error
c) o
False
d) None of the mentioned
View Answer

Answer: c
Explanation: The array is a string array and the index is 3 so ‘o’ will be the output and then the boolean_array[1] = false will get printed.

Output:
o
False

6. What is the output of the given code?

a=[1,2,3,4,5]
b=[1,2,4,6,8]
if a[3]==b[2]
    print "Equal"
end

a) Equal
b) Error
c) 4
d) None of the mentioned
View Answer

Answer: a
Explanation: a[3]=4 and b[2]=4 hence it will print equal according to the given if condition.

Output:
Equal

7. What is the output of the given code?

a=[1,2,3,4,5]
b=[1,2,3,4,5]
if a==b
    print "Equal"
else
    print "Not equal"
end

a) Equal
b) Error
c) Not equal
d) None of the mentioned
View Answer

Answer: a
Explanation: Elements of both the array are same hence they are equal.

Output:
Equal

8. What is the output of the given code?

a=["hey", "ruby", "language"]
b=["hey", "ruby", "language"]
if a==b
    print "Equal"
else
    print "Not equal"
end

a) Equal
b) Error
c) Not equal
d) None of the mentioned
View Answer

Answer: a
Explanation: Elements of both the array are same and in same sequence hence they are equal.

Output:
Equal

9. What is the output of the given code?

a=["hey", "ruby", "language"]
b=["hey", "language", "ruby"]
if a==b
    print "Equal"
else
    print "Not equal"
end

a) Equal
b) Error
c) Not equal
d) None of the mentioned
View Answer

Answer: c
Explanation: Elements of both the array are same but not in same sequence hence they are not equal.

Output:
Not equal

10. What is the output of the given code?

a=["hey", "ruby", "language"]
b=[1, 2, 3]
puts b[1]
puts a[2]

a) 3 ruby
b) Error
c) 2
language
d) None of the mentioned
View Answer

Answer: c
Explanation: b[1]=2 and a[2]=language hence these both will get printed.

Output:
2
language
Sanfoundry Global Education & Learning Series – Ruby Programming.

To practice all areas of Ruby Programming for Interviews, 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.