Commerce

Basic Syntax In Ruby MCQs

Practice Basic Syntax In Ruby MCQs for competitive exams.

Basic Syntax In Ruby MCQs

Practice questions from this topic.

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. A. amil jones
  2. B. What's your first name? amil My name is Amil
  3. C. What's your first name? amil My name is limA
  4. D. My name is limA
Report Error

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. A. 12,48,40
  2. B. Syntax error
  3. C. The value of x is 12. The sum of x and y is 48. The average was 40.
  4. D. None of the mentioned
Report Error

Why do we use =begin and =end?

  1. A. To mark the start and end of multiline comment
  2. B. To comment multiple lines
  3. C. To avoid the use of # again and again
  4. D. All of the mentioned
Report Error

Which of the following type of comments are valid in ruby?

  1. A. Single line comments
  2. B. Multi line comments
  3. C. Double line comments
  4. D. All of the mentioned
Report Error

What is the range of octal notation (nnn)?

  1. A. 0-8
  2. B. 0-7
  3. C. 0-A
  4. D. None of the mentioned
Report Error

What will be the output of the given code? "I'am learning Ruby Language".length.reverse.upcase

  1. A. 27
  2. B. egaugnal ybuR gninreal ma'I
  3. C. ERAUGNAL YBUR GNINREAL MA'I
  4. D. Undefined method 'reverse' for 27:Fixnum
Report Error

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

  1. A. It is the syntax for using capitalize method
  2. B. It modifies the value stored in the variable
  3. C. It indicates the termination of string
  4. D. None of the mentioned
Report Error

Which of the following are valid floating point literal?

  1. A. .5
  2. B. 2
  3. C. 0.5
  4. D. None of the mentioned
Report Error

What will be the output of the following? "Ruby".reverse.upcase

  1. A. RUBY
  2. B. ybuR
  3. C. YBUR
  4. D. YBUr
Report Error

Ruby is a case-sensitive language.

  1. A. True
  2. B. False
Report Error

Why is the library function 'puts'used for?

  1. A. Prints whatever is given and print it to the screen
  2. B. Prints whatever is given and insert a new(blank) line
  3. C. Gets input from the user
  4. D. None of the mentioned
Report Error

It is must for Ruby to use a compiler.

  1. A. True
  2. B. False
Report Error