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 correct syntax for defining a variable in Ruby?

  1. A. var name = "value"
  2. B. variable name = value
  3. C. name = value
  4. D. name: value
Report Error

Which of the following is NOT a valid data type in Ruby?

  1. A. Integer
  2. B. Float
  3. C. Double
  4. D. String
Report Error

What does the 'gets' method do in Ruby?

  1. A. Prints to console
  2. B. Converts to string
  3. C. Reads input from user
  4. D. Finds the length
Report Error

Which of the following is a valid variable name in Ruby?

  1. A. my_variable
  2. B. 123variable
  3. C. _variable
  4. D. variable-1
Report Error

In Ruby, what is the keyword used to define a method?

  1. A. function
  2. B. define
  3. C. method
  4. D. def
Report Error

What does the 'puts' method do in Ruby?

  1. A. Prints to console
  2. B. Converts to string
  3. C. Finds the length
  4. D. Reads input from user
Report Error

Which symbol is used to concatenate strings in Ruby?

  1. A. +
  2. B. .
  3. C. :
  4. D. <<
Report Error

What symbol is used to denote comments in Ruby?

  1. A. //
  2. B. #
  3. C. --
  4. D. /* */
Report Error