Ruby/Ruby Multiple Choice Questions Set 1 Sample Test,Sample questions

Question:
 If expression.
The expression can be of which type?

1.True

2.Any number

3.Any string

4.All of the mentioned


Question:
 What is the output of given code?

 string="I'am Learning RUBY Language".downcase
    string.upcase

1.Undefined method

2.“I’AM LEARNING RUBY LANGUAGE

3.I’am Learning RUBY Language

4.None of the mentioned


Question:
 What is the output of the code?

print "What's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   first_name.capitalize!
   print "What's your last name?"
   last_name=gets.chomp
   b=last_name.capitalize
   last_name.capitalize!
   puts "My name is #{first_name} #{last_name}"

1.Amil Jones

2.What’s your first name? amil What’s your last name? jones My name is Amil Jones

3.My name is Amil Jones

4.None of the mentioned


Question:
 What is the output of the given code?

 a = 5
b=10
while a <10 || b<20
  puts a*b
  a+=2
  b+=2
  end

1.0 20

2.50 84 126 176 234

3.-5 -5 -5

4.None of the mentioned


Question:
 What is the output of the given code?

"Ruby Language".length
       = begin
       calculate length
       = end

1.13

2.12

3.Error

4.None of the mentioned


Question:
 What is the output of the given code?

a = 22.5
while a >11.5
  puts a
  a-=3.5
  end

1. 22.5 19.0 15.5 12.0

2.22.5 11.5

3.100..5

4.None of the mentioned


Question:
 What is the output of the given code?

a = 5
b=10
while a <10 && b<20
  puts a*b
  a+=2
  b+=2
  end

1.10 20

2.15 19 23

3.50 84 126

4.None of the mentioned


Question:
 What is the output of the given code?

Ans=Ruby
    puts "#[Ans] is an oop language"

1.Error, no output

2.Ruby is an oop language

3.Warning:already initialized constant Ans

4.None of the mentioned


Question:
 What is the output of the given code?

my_string=Ruby
    puts(my_string)

1.Ruby

2.Nil

3.Error

4.None of the mentioned


Question:
 What is the range of octal notation (
nn)?

1.0-8

2.0-7

3.0-A

4.None of the mentioned


Question:
 What will be the output of the following?

"Eric".irreverse

1.Eric

2.cirE

3.undefined method

4.None of the mentioned


Question:
 What will be the output of the following?

"Ruby".reverse.upcase

1.RUBY

2.ybuR

3.YBUR

4.YBUr


Question:
 What will be the output of the given code?

 boolean_1 = false || -10 > -9
puts boolean_1

1.True

2.False

3.Error

4.None of the mentioned


Question:
 What will the following expression evaluate to?
true && false

1.True

2.False

3.Error

4.None of the mentioned


Question:
 Which of the following is a valid assignment operator?

1.+=

2.-=

3.*=

4.All of the mentioned


Question:
 Which of the following is a valid boolean operator?

1.and(&&)

2. or(||)

3.not(!)

4.All of the mentioned


Question:
 Which of the following is supported by Ruby?

1.Multiple Programming Paradigms

2.Dynamic Type System

3.Automatic Memory Management

4.All of the Mentioned


Question:
 Which of the following is the valid string method?

1.The .length method

2.The .upcase method

3.The .downcase method

4. The .irreverse method


Question:
 Why do we use comments?

1.For later use to understand the working of the program

2.It is an efficient way of programming

3.It makes easy for the third person to understand

4.All of the Mentioned


Question:
For getting an input from the user which method is used?

1.get

2. gets.chomp

3.get-s

4.chomp


Question:
How to comment a single line?

1.Using #

2.Using begin and end

3.Using //

4.None of the mentioned


Question:
How to comment multiple lines in ruby?

1.Using multiline comments

2.Using single line comments

3.No option to comment

4.All of the mentioned


Question:
How to comment multiple lines in ruby?
a) 

1.Using multiline comments

2.No option to comment

3.Using single line comment

4.All of the mentioned


Question:
Objects of which class does the integer from the range -2^30 to 2^(30-1) belong to?

1.Bignum

2.Octal

3.Fixnum

4.Binary


Question:
What do we mean by expression substitution?

1.Embedding the value of Ruby expression into a string using #{ }

2. Substituting string functions

3.Storing string value

4.None of the mentioned


Question:
What does %Q{ Learn ruby language } represents?
a) ” 

1.Learn Ruby language ”

2.“%{ Learn Ruby language }”

3.Learn Ruby language

4.None of the mentioned


Question:
What does %x!ls! represents?

1.Same as back tick command output `ls`

2.Same as ‘x’

3.Same as “xls”

4.None of the mentioned


Question:
What does %{Learn ruby language} represents?
a) “
b) “%{Learn Ruby language}”
c) ” 
d) None of the mentioned

1.Learn Ruby language”

2. “%{Learn Ruby language}”

3.Learn Ruby language ”

4.None of the mentioned


Question:
What does the **= assignment operator do?

1.Multiplies the value twice

2.It is used as exponent like 2**3=8

3. It is the multiplication operator.

4.None of the mentioned


Question:
What does the .upcase method do?

1. Convert the string to uppercase

2.Convert only lowercase string to uppercase and vice-versa

3.Convert the string to lowercase

4.None o the mentioned


Question:
What does the notataion  stands for?

1.Escape

2.Space

3.Backspace

4.Newline


Question:
What is the extension used for saving the ruby file?

1.ruby extension

2..rb extension

3.rrb extension

4.None of the mentioned


Question:
What is the output of given code?

puts "what is your first name?"
   name=gets.chomp
   puts "what is your surname?"
   surname=gets.chomp

1.Error in compilation

2.What is your first name? xyz(enter any name) What is your surname? wtu(enter your surname)

3.Name=xyz

4. None of the mentioned


Question:
What is the output of the code?

 if 11<2
   print "Eleven is less than two"
   end
   print "11 is greater"

1.11 is greater

2.Eleven is less than two

3.Eleven is less than two 11 is greater

4.None of the mentioned


Question:
What is the output of the code?

print "What's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   first_name.capitalize!
   print "What's your last name?"
   last_name=gets.chomp
   b=last_name.capitalize
   last_name.capitalize
   puts "My name is #{first_name} #{last_name}"

1.Amil Jones

2.What’s your first name? amil What’s your last name? jones My name is Amil Jones

3.What’s your first name? amil What’s your last name? jones My name is Amil jones

4.None of the mentioned


Question:
What is the output of the following?

if 1<2
   print "one is less than two"
   end

1.One is less than two

2.Syntax error

3.1<2

4.None of the mentioned


Question:
What is the output of the following?
"Iam learning ruby language".length

1.26

2.23

3.20

4.18


Question:
What is the output of the given code?

 a = 5
b=10
while (a <10 || b<20)&&true
  puts a*b
  a+=2
  b+=2
  end

1.10 20

2.50 84 126 176 234

3. -5 -5 -5

4.None of the mentioned


Question:
What is the output of the given code?

 a= 5
b=10
while a <10 && b<20
  puts a-b
  a+=2
  b+=2
  end

1.10 20

2.15 19 23

3.-5 -5 -5

4.None of the mentioned


Question:
What is the output of the given code?

 print "What's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   a=a.reverse
   puts"My name is #{a}"

1.amil jones

2.What’s your first name? amil My name is Amil

3.What’s your first name? amil My name is limA

4.My name is limA


Question:
What is the output of the given code?

 x, y, z = 12, 36, 72
    puts "The value of x is #{ x }."
    puts "The sum of x and y is #{ x + y }."
    puts "The average was #{ (x + y + z)/3 }."

1.12,48,40

2.Syntax error

3.The value of x is 12. The sum of x and y is 48. The average was 40.

4.None of the mentioned


Question:
What is the output of the given code?

"Ruby Language".length
       =begin
       calculate length
       =end

1.13

2.13 calculate length

3.12

4.None of the mentioned


Question:
What is the output of the given code?

a = 5
b=10
while a <10 && b<20
  puts a+b
  a+=2
  b+=2
  end

1.10 20

2.15 19 23

3.15 16 17 18 19 20

4.None of the mentioned


Question:
What is the output of the given code?

a="string"
b="strings"
if(a==b)
    print ("a and b are same")
else 
    print "Not same"
end

1.a and b are same

2.Not same

3.a==b

4.None of the mentioned


Question:
What is the output of the given code?

a=10
b=9
if(a>b)
    print ("a greater than b")
else 
    print "Not greater"
end

1.a greater than b

2. Not greater

3.Syntax error

4.None of the mentioned


Question:
What is the output of the given code?

Ans=Ruby
    puts "#{Ans} is an oop language"
    puts "It is very efficient langauge"
    puts "#{expr} is used on rails platform"

1.Error, no output

2.Ruby is an oop language It is very efficient langauge undefined local variable

3.Ruby is an oop language It is very efficient langauge #{expr} is used on rails platform

4.None of the mentioned


Question:
What is the output of the given code?

boolean_1 = 77<78
   puts(boolean_1)

1. Nil

2.True

3.False

4.Error


Question:
What is the output of the given code?

counter = -50
while counter <0
  puts counter
  counter+=10
  end

1.100 75 50 25

2.-50 -40 -30 -20 -10

3.100..5

4.None of the mentioned


Question:
What is the output of the given code?

counter = 1
while counter < 11
  puts counter
  counter+=1
  end

1.1 2 3 4 5

2.1…10

3.1..10

4.None of the mentioned


Question:
What is the output of the given code?

counter = 100
while counter > 0
  puts counter
  counter-=25
  end

1.100 75 50 25

2.100 25 5

3.100..5

4.None of the mentioned


Question:
What is the output of the given code?

counter = 100
while counter > 0
  puts counter
  counter/=5
  end

1.100 20 4

2.100 20 5

3.100..5

4.None of the mentioned


Question:
What is the output of the given code?

counter=1
if counter<=5
    puts (counter)
    counter=counter+1

1.Syntax error

2. 1 2

3.1

4.None of the mentioned


Question:
What is the output of the given code?

if 11>2
   puts "Eleven is greater than two"
   end
   print "You'r right"

1. Eleven is greater than two

2. You’r right

3.Eleven is greater than two You’r right

4.None of the mentioned


Question:
What is the output of the given code?

if(a==10 && b=9)
    print "true"
else
    print "false"
end

1.True

2.False

3.Error

4.None of the mentioned


Question:
What is the output of the given code?

print "What's your address"
    city,state,pin=gets.chomp,gets.chomp,gets.chomp
    puts "Iam from #{city} city, #{state} state, pincode: #{pin} "

1.Error in compilation

2.Give your address

3.What’s your address? Chennai Tamilnadu 600048 Iam from Chennai city, Tamilnadu state, pincode: 600048

4.None of the mentioned


Question:
What is the output of the given code?

print "what's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   "a".reverse
   puts"My name is #{a}"

1.mil jones

2.What’s your first name? amil My name is Amil

3.My name is lima

4.My name is limA


Question:
What is the output of the given code?

print "what's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   "first_name.capitalize!".reverse
   puts"My name is #{first_name}"

1.amil jones

2.What’s your first name? amil My name is amil

3.My name is lima

4.My name is limA


Question:
What is the output of the given code?

test_1 = 17 > 16
puts(test_1)
test_2 = 21 <= 30
puts(test_2)
test_3 = 9 >= 9
puts(test_3)
test_4 = -11 > 4
puts(test_4)

1.True false true false

2.True True True False

3.False False True True

4.None of the mentioned


Question:
What is the output of the given code?
“Ruby”.length #to find the length of given string

1.4 to find the length of given string

2.4

3.To find the length of given string

4.Ruby


Question:
What is the output of the the given code?

 puts "My name is #{Name}"

1.Error in compilation

2.Name variable not defined earlier

3.My name is #{Name}

4.Undefined Error


Question:
What is the role of ! at the end of the capitalize method?

1.It is the syntax for using capitalize method

2.It modifies the value stored in the variable

3.It indicates the termination of string

4.None of the mentioned


Question:
What is the size of an integer data type in ruby?

1.-230 to 230

2.-230 to 2(30-1)

3.-229 to 230

4.-260 to 261


Question:
What is the use of .capitalize method?

1.It capitalizes the entire string

2.It capitalize on the first letter of the string

3.It capitalize the strings which are in small case

4.All of the mentioned


Question:
What will any variable evaluate to if it is of Boolean data type?

1.True

2.Nil

3.False

4.Either True or False


Question:
What will be the output of the given code?

 boolean_1 = !(3 < 4 || false) && (false || true)
puts boolean_1

1.True

2.False

3.Error

4.None of the mentioned


Question:
What will be the output of the given code?

 boolean_1 = !(700 / 10 == 70)
puts boolean_1

1.True

2.False

3.Error

4.None of the mentioned


Question:
What will be the output of the given code?

 boolean_1 = !true
puts boolean_1  
boolean_2 = !true && !true
puts boolean_2

1.True True

2.False False

3.True False

4.None of the mentioned


Question:
What will be the output of the given code?

 boolean_1 = (3 < 4 || false) && (false || true)
puts boolean_1

1.True

2.False

3.Error

4.None of the mentioned


Question:
What will be the output of the given code?

 boolean_2 = !true && (!true || 100 != 5**2)
puts boolean_2

1.True

2.False

3.Error

4.None of the mentioned


Question:
What will be the output of the given code?

"Come let's learn.reverse Ruby.length language".upcase

1.nreal s’tel emoC 4 LANGUAGE

2.Undefined error

3.COME LET’S LEARN.REVERSE RUBY.LENGTH LANGUAGE

4.All of the above


Question:
What will be the output of the given code?

"I'am learning Ruby Language".length.reverse.upcase

1.27

2.egaugnal ybuR gninreal ma’I

3.ERAUGNAL YBUR GNINREAL MA’I

4.Undefined method `reverse’ for 27:Fixnum


Question:
What will be the output of the given code?boolean_1 = 77 < 78 && 77 < 77
puts boolean_1

1. True

2.False

3.Error

4.None of the mentioned


Question:
What will the following expression evaluate to?
!true && !false

1. True

2.False

3.Error

4. None of the mentioned


Question:
What will the following expression evaluate to?
(true && false) || (!true)

1.True

2.False

3.Error

4.None of the mentioned


Question:
What will the following expression evaluate to?
true || false mentioned

1.True

2.False

3.Error

4.None of the mentioned


Question:
What will we the output of the given code?

 "I'am Learning RUBY Language".downcase

1. iam learning ruby language

2.i’AM lEARNING ruby lANGUAGE

3.i’am learning ruby language

4.None of the mentioned


Question:
What will we the output of the given code?

I'am Learning RUBY Language.downcase

1. iam learning ruby language

2.i’AM lEARNING ruby lANGUAGE

3.i’am learning ruby language”

4.unterminated string meets end of file


Question:
Which of the following are used for comparison?

1.Equal to

2.Not equal to

3.Less than or greater than

4.All of the mentioned


Question:
Which of the following are valid floating point literal?

1..5

2.2

3. 0.5

4.None of the mentioned


Question:
Which of the following datatypes are valid in Ruby?

1.Numbers

2.Boolean

3.String

4.All of the mentioned


Question:
Which of the following features does the 2.0 version of ruby supports?

1.Method keyword arguments

2.New literals

3.Security fixes

4.All of the mentioned


Question:
Which of the following is not a valid datatype?

1.Float

2.Integer

3.Binary

4.Timedate


Question:
Which of the following is not a valid library function?

1.Puts

2. Print

3.Gets

4.Get


Question:
Which of the following is not a valid library function?

1.Puts

2.Print

3.Gets

4.Get


Question:
Which of the following languages syntax matches with the Ruby’s syntax?

1.Perl

2.PHP

3.Java

4.Jquery


Question:
Which sequence can be used to substitute the value of any ruby expression in a string?

1.#(expr)

2.#{expr}

3.#expr

4.None of the mentioned


Question:
Why can not we use quotation marks (‘ or “) with boolean?

1.It indicates that we are talking about a string

2.It indicates that we are assining a value

3.It indicates that that we are replacing boolean data type with string data type

4.None of the mentioned


Question:
Why do we use =begin and =end?

1.To mark the start and end of multiline comment

2.To comment multiple lines

3.To avoid the use of # again and again

4.All of the mentioned


Question:
Why is gets not preferred instead of gets.chomp?

1.Gets add an extra new line while chomp removes it

2.Gets remove an extra new line

3.Chomp erases the value stored in the variable

4.All of the mentioned


Question:
Why is the library function ‘puts’used for?

1.Prints whatever is given and print it to the screen

2.Prints whatever is given and insert a new(blank) line

3.Gets input from the user

4.None of the mentioned


More MCQS

  1. Ruby Multiple Choice Questions Set 1
  2. Ruby Multiple Choice Questions Set 2
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!