Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Space between 2+5 or 2 + 5 is valid but =begin and = begin is not valid.(a) True(b) FalseI got this question in an international level competition.My question is taken from Comments in Ruby in chapter Ruby Basics of Ruby

Answer»

The CORRECT ANSWER is (a) True

The EXPLANATION is: Ruby recognizes =begin and = begin in DIFFERENT WAY.

2.

Why do we use =begin and =end?(a) To mark the start and end of multiline comment(b) To comment multiple lines(c) To avoid the use of # again and again(d) All of the mentionedI have been asked this question during an online exam.Origin of the question is Comments in Ruby in portion Ruby Basics of Ruby

Answer»

The CORRECT choice is (d) All of the mentioned

The explanation: Easier way to COMMENT multiple LINES.

3.

This the right way to comment a single line.(a) “Ruby”.length # I’m a single line comment!(b) True(c) FalseThis question was addressed to me in final exam.My question comes from Comments in Ruby in portion Ruby Basics of Ruby

Answer» RIGHT OPTION is (a) “RUBY”.length # I’m a single line comment!

To EXPLAIN: We use # in a single line comment.
4.

Why do we use comments?(a) For later use to understand the working of the program(b) It is an efficient way of programming(c) It makes easy for the third person to understand(d) All of the mentionedThis question was posed to me in my homework.The doubt is from Comments in Ruby topic in section Ruby Basics of Ruby

Answer» RIGHT choice is (d) All of the mentioned

Best EXPLANATION: It is the EFFICIENT way of programming and EASY to UNDERSTAND.
5.

How to comment a single line?(a) Using #(b) Using begin and end(c) Using //(d) None of the mentionedI got this question during an internship interview.The doubt is from Comments in Ruby in division Ruby Basics of Ruby

Answer»

The correct answer is (a) USING #

The best explanation: USE # to COMMENT SINGLE line.

6.

Which of the following type of comments are valid in ruby?(a) Single line comments(b) Multi line comments(c) Double line comments(d) All of the mentionedThe question was posed to me in class test.The origin of the question is Comments in Ruby topic in portion Ruby Basics of Ruby

Answer»

The correct option is (d) All of the mentioned

Easy EXPLANATION: Double LINE COMMENTS comes under multiline COMMENT.

7.

How to comment multiple lines in ruby?(a) Using multiline comments(b) Using single line comments(c) No option to comment(d) All of the mentionedThis question was posed to me during an interview for a job.The question is from Comments in Ruby in division Ruby Basics of Ruby

Answer»

The CORRECT CHOICE is (a) USING multiline comments

To explain I would say: MULTIPLE lines can be commented using multiline comments.

8.

What does %x!ls! represents?(a) Same as back tick command output `ls`(b) Same as ‘x’(c) Same as “xls”(d) None of the mentionedI had been asked this question by my school principal while I was bunking the class.Query is from Formatting String Methods topic in portion Ruby Basics of Ruby

Answer» RIGHT answer is (a) Same as back tick COMMAND output `LS`

To explain: It is same as back tick command output `ls`.
9.

What does %{Learn ruby language} represents?(a) “Learn Ruby language”(b) “%{Learn Ruby language}”(c) ” Learn Ruby language ”(d) None of the mentionedI had been asked this question in an online quiz.I want to ask this question from Formatting String Methods topic in chapter Ruby Basics of Ruby

Answer»

Right option is (a) “LEARN RUBY LANGUAGE

The best explanation: Anything written INSIDE %{} is same as anything written inside “”.

10.

What do we mean by expression substitution?(a) Embedding the value of Ruby expression into a string using #{}(b) Substituting string functions(c) Storing string value(d) None of the mentionedThis question was addressed to me by my college director while I was bunking the class.The doubt is from Formatting String Methods in section Ruby Basics of Ruby

Answer» RIGHT answer is (a) EMBEDDING the value of Ruby expression into a string using #{}

Explanation: STRINGS are DISPLAYED #{} sequence.
11.

What does %Q{ Learn ruby language } represents?(a) ” Learn Ruby language ”(b) “%{ Learn Ruby language }”(c) ” Learn Ruby language ”(d) None of the mentionedThis question was posed to me in an interview for job.The doubt is from Formatting String Methods in portion Ruby Basics of Ruby

Answer» CORRECT OPTION is (a) ” Learn Ruby language ”

The best I can explain: ANYTHING inside %Q{} is WRITTEN inside “”.
12.

What is the role of ! at the end of the capitalize method?(a) It is the syntax for using capitalize method(b) It modifies the value stored in the variable(c) It indicates the termination of string(d) None of the mentionedI got this question by my school principal while I was bunking the class.I need to ask this question from Formatting String Methods topic in division Ruby Basics of Ruby

Answer»

The CORRECT OPTION is (B) It MODIFIES the value STORED in the variable

Easiest explanation: It is used for modifying the variable.

13.

What is the use of .capitalize method?(a) It capitalizes the entire string(b) It capitalize on the first letter of the string(c) It capitalize the strings which are in small case(d) All of the mentionedI got this question by my college director while I was bunking the class.I'd like to ask this question from Formatting String Methods in chapter Ruby Basics of Ruby

Answer»

The CORRECT choice is (b) It CAPITALIZE on the first LETTER of the string

Easy EXPLANATION: It capitalizes only the first letter.

14.

Methods should not be written inside double quotes.(a) True(b) FalseI had been asked this question during an online exam.Enquiry is from String Methods topic in portion Ruby Basics of Ruby

Answer»

Right choice is (a) True

To EXPLAIN I would SAY: Always make SURE to write methods outside DOUBLE quotes.

15.

The .upcase and .capitalize method are used for capitalizing the whole string.(a) True(b) FalseI had been asked this question in an interview for job.My doubt is from Formatting String Methods topic in chapter Ruby Basics of Ruby

Answer» RIGHT CHOICE is (b) False

To elaborate: The .capitalize method doesn’t change the whole string to uppercase, it just CAPITALIZES the FIRST letter.
16.

The downcase method changes the whole string to smallcase letters.(a) True(b) FalseI had been asked this question in examination.Query is from String Methods topic in chapter Ruby Basics of Ruby

Answer» CORRECT CHOICE is (a) True

The EXPLANATION is: CHANGES EVERYTHING to smallcase.
17.

The .length method is used to check number of characters.(a) True(b) FalseThe question was asked during an interview.The above asked question is from String Methods in section Ruby Basics of Ruby

Answer» RIGHT answer is (b) False

The explanation is: The .length method is used to check number of characters, SPACES and EVEN symbols.
18.

What does the .upcase method do?(a) Convert the string to uppercase(b) Convert only lowercase string to uppercase and vice-versa(c) Convert the string to lowercase(d) None o the mentionedI got this question in unit test.The above asked question is from String Methods in section Ruby Basics of Ruby

Answer»

Right option is (a) Convert the string to UPPERCASE

The best EXPLANATION: .upcase method is USED to CHANGE the GIVEN string to uppercase.

19.

Which of the following is the valid string method?(a) The .length method(b) The .upcase method(c) The .downcase method(d) The .irreverse methodI got this question by my school teacher while I was bunking the class.This key question is from String Methods topic in chapter Ruby Basics of Ruby

Answer»

The CORRECT ANSWER is (d) The .irreverse method

For EXPLANATION: There is no PREDEFINED method which can reverse an already reversed string.

20.

first_name,Last_name=gets.chomp,gets.chomp is the correct way to get the input from the user.(a) True(b) FalseThis question was addressed to me by my college professor while I was bunking the class.This question is from Library Functions topic in portion Ruby Basics of Ruby

Answer» RIGHT choice is (a) True

To explain: It will TAKE the input from user and STORE its value in the specified VARIABLES.
21.

Why is gets not preferred instead of gets.chomp?(a) Gets add an extra new line while chomp removes it(b) Gets remove an extra new line(c) Chomp erases the value stored in the variable(d) All of the mentionedI had been asked this question during an internship interview.The query is from Library Functions in portion Ruby Basics of Ruby

Answer»

Right CHOICE is (a) Gets ADD an EXTRA new line while chomp removes it

The explanation is: gets.chomp will remove the extra BLANK space.

22.

Which sequence can be used to substitute the value of any ruby expression in a string?(a) #(expr)(b) #{expr}(c) #expr(d) None of the mentionedThis question was addressed to me in homework.This intriguing question originated from Library Functions topic in portion Ruby Basics of Ruby

Answer»

The correct ANSWER is (B) #{expr}

To explain: #{expr} is valid.

23.

For getting an input from the user which method is used?(a) get(b) gets.chomp(c) get-s(d) chompThe question was asked during an interview.This is a very interesting question from Library Functions topic in chapter Ruby Basics of Ruby

Answer» CORRECT answer is (b) gets.chomp

To explain I would say: The METHOD gets.chomp TAKES the INPUT from the USER.
24.

We use semicolon or parentheses after every print or puts statement.(a) True(b) FalseThis question was addressed to me in homework.Question is taken from Library Functions in section Ruby Basics of Ruby

Answer» RIGHT choice is (b) False

Explanation: No SEMICOLON or PARENTHESES is required.
25.

Why is the library function ‘puts’used for?(a) Prints whatever is given and print it to the screen(b) Prints whatever is given and insert a new(blank) line(c) Gets input from the user(d) None of the mentionedThe question was asked during an online interview.My question is from Library Functions topic in portion Ruby Basics of Ruby

Answer»

Correct choice is (b) Prints WHATEVER is given and insert a new(blank) LINE

The BEST I can explain: Puts is a LIBRARY function which prints and then insert a new blank line.

26.

Which of the following is not a valid library function?(a) Puts(b) Print(c) Gets(d) GetI had been asked this question during an internship interview.This is a very interesting question from Library Functions in chapter Ruby Basics of Ruby

Answer»

The correct OPTION is (d) Get

Explanation: gets is USED for TAKING input from the USER.

27.

What is the range of octal notation (\nnn)?(a) 0-8(b) 0-7(c) 0-A(d) None of the mentionedI got this question in class test.My enquiry is from Data Types and Variables topic in division Ruby Basics of Ruby

Answer»

The CORRECT OPTION is (b) 0-7

To EXPLAIN I would SAY: Octal notation ranges from0-7.

28.

Which of the following is not a valid datatype?(a) Float(b) Integer(c) Binary(d) TimedateI got this question in an interview for job.The origin of the question is Data Types and Variables in chapter Ruby Basics of Ruby

Answer»

The CORRECT OPTION is (d) Timedate

To explain: datetime is valid DATATYPE but timedate is not a valid datatype.

29.

What is the sequence of ruby strings?(a) 16-bit bytes(b) 8-bit bytes(c) 10-bit bytes(d) None of the mentionedI had been asked this question in an online quiz.My question is based upon Data Types and Variables topic in portion Ruby Basics of Ruby

Answer»

The correct option is (b) 8-bit bytes

Easiest explanation: They are SIMPLY the SEQUENCE of 8-bit bytes.

30.

What does the notataion \b stands for?(a) Escape(b) Space(c) Backspace(d) NewlineThis question was addressed to me in exam.The above asked question is from Data Types and Variables topic in division Ruby Basics of Ruby

Answer»

The CORRECT option is (C) Backspace

The best I can EXPLAIN: This notataion is USED for backspace.

31.

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) BinaryThis question was addressed to me in an interview for internship.I'd like to ask this question from Data Types and Variables in section Ruby Basics of Ruby

Answer»

The CORRECT choice is (c) FIXNUM

The best explanation: Integer within this RANGE are objects of the CLASS fixnum.

32.

Ruby can deal with both numbers and floating point values.(a) True(b) FalseThis question was addressed to me in an interview for job.This question is from Data Types and Variables topic in portion Ruby Basics of Ruby

Answer» RIGHT ANSWER is (a) True

For explanation I would say: We can assingn a integer and a floating point VALUE to a variable.
33.

Ruby is a case-sensitive language.(a) True(b) FalseI had been asked this question in an online interview.Question is taken from Data Types and Variables topic in division Ruby Basics of Ruby

Answer» RIGHT ANSWER is (a) True

Explanation: RUBY differentiates between SMALL and capital letters and their MEANING.
34.

What is the size of an integer data type in ruby?(a) -2^30 to 2^30(b) -2^30 to 2^(30-1)(c) -2^29 to 2^30(d) -2^60 to 2^61I got this question by my school teacher while I was bunking the class.I want to ask this question from Data Types and Variables topic in chapter Ruby Basics of Ruby

Answer» CORRECT OPTION is (B) -2^30 to 2^(30-1)

Explanation: Integer ranges from -2^30 to 2^29 and lies in OBJECT of CLASS Fixnum.
35.

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 mentionedI had been asked this question in an internship interview.Asked question is from Data Types and Variables in section Ruby Basics of Ruby

Answer»

The correct OPTION is (a) It INDICATES that we are TALKING about a string

The best explanation: Quotation marks are USED only with strings.

36.

What will any variableevaluate to if it is of Boolean data type?(a) True(b) Nil(c) False(d) Either True or FalseThis question was addressed to me in an interview for job.My question is based upon Data Types and Variables in portion Ruby Basics of Ruby

Answer»

The CORRECT CHOICE is (d) EITHER True or False

To explain I would say: Boolean data types will give the VALUE either as True or False depending on the condition.

37.

Ruby can be used for developing internet and intranet applications.(a) True(b) FalseI got this question in an internship interview.I'm obligated to ask this question of Basics in chapter Ruby Basics of Ruby

Answer»

The correct CHOICE is (a) True

The best I can explain: Ruby is a server side scripting LANGUAGE used to create CGI(COMMON gateway interface) scripts and hence can be used for developing internet and intranet applications.

38.

Which of the following datatypes are valid in Ruby?(a) Numbers(b) Boolean(c) String(d) All of the mentionedThe question was posed to me in an interview for internship.The query is from Data Types and Variables topic in chapter Ruby Basics of Ruby

Answer» RIGHT CHOICE is (d) All of the mentioned

Best explanation: Ruby SUPPORTS all the three (numbers,strings,boolean) DATA types.
39.

It is must for Ruby to use a compiler.(a) True(b) FalseThis question was posed to me at a job interview.My question is from Basics in portion Ruby Basics of Ruby

Answer»

Right OPTION is (b) False

The explanation: No COMPILER is required for ruby as it is an INTERPRETED language.

40.

Ruby can be embedded into Hypertext Markup Language(HTML).(a) True(b) FalseThe question was asked in an interview for job.This interesting question is from Basics topic in section Ruby Basics of Ruby

Answer»

Right CHOICE is (a) True

To explain I would SAY: RUBY can EASILY be encapsulated into HTML.

41.

Which of the following are valid floating point literal?(a) .5(b) 2(c) 0.5(d) None of the mentionedThis question was posed to me during an interview for a job.This intriguing question comes from Basics in section Ruby Basics of Ruby

Answer»

The correct OPTION is (c) 0.5

Easiest explanation: floating POINT LITERALS are VALID only when they have digits on both the sides of decimal point.

42.

What is the extension used for saving the ruby file?(a) .ruby extension(b) .rb extension(c) .rrb extension(d) None of the mentionedThe question was posed to me during a job interview.This interesting question is from Basics in portion Ruby Basics of Ruby

Answer»

The correct ANSWER is (b) .rb EXTENSION

For explanation: RUBY files must be SAVED with the extension .rb.

43.

Which of the following languages syntax matches with the Ruby’s syntax?(a) Perl(b) PHP(c) Java(d) JqueryThis question was addressed to me during an interview for a job.My query is from Basics in portion Ruby Basics of Ruby

Answer»

The correct CHOICE is (a) PERL

The best explanation: Most of the SYNTAX of perl LANGUAGE matches with that of Ruby’s.

44.

Which of the following features does the 2.0 version of ruby supports?(a) Method keyword arguments(b) New literals(c) Security fixes(d) All of the mentionedThis question was addressed to me in an online quiz.This intriguing question originated from Basics topic in section Ruby Basics of Ruby

Answer»

The CORRECT CHOICE is (d) All of the mentioned

For EXPLANATION: Ruby2.0 has several new added features and it is much STABLE than its older versions.

45.

Which of the following is supported by Ruby?(a) Multiple Programming Paradigms(b) Dynamic Type System(c) Automatic Memory Management(d) All of the MentionedI had been asked this question in an interview for internship.This interesting question is from Basics in portion Ruby Basics of Ruby

Answer»

The correct option is (d) All of the Mentioned

Easy explanation: RUBY supports all the FEATURES because it is a object ORIENTED programming LANGUAGE.

46.

Ruby is an object oriented general purpose programming language.(a) True(b) FalseI had been asked this question in exam.My question comes from Basics topic in portion Ruby Basics of Ruby

Answer»

The CORRECT CHOICE is (a) True

To elaborate: Ruby allow USERS to manipulate data STRUCTURES called objects to BUILD and execute programs.