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.

In Ruby, what is the keyword used to define a loop that repeats until a condition is true?

  1. A. until
  2. B. loop
  3. C. while
  4. D. repeat
Report Error

What is the output of the expression: "hello" + "world" in Ruby?

  1. A. helloworld
  2. B. hello world
  3. C. hello+world
  4. D. "hello" "world"
Report Error

Which method is used to find the length of an array in Ruby?

  1. A. .size
  2. B. .length
  3. C. .count
  4. D. .length_of
Report Error

What is the correct syntax for a multiline comment in Ruby?

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

Which of the following is the correct way to define a range in Ruby?

  1. A. (1..10)
  2. B. [1 to 10]
  3. C. {1..10}
Report Error

In Ruby, what is the correct way to define a constant?

  1. A. constant_name = value
  2. B. constant name : value
  3. C. CONSTANT_NAME = value
  4. D. constant_name(value)
Report Error

What does the 'return' keyword do in Ruby methods?

  1. A. Exits the method with a value
  2. B. Prints to console
  3. C. Converts to integer
  4. D. Continues the loop
Report Error

Which method is used to convert a string to lowercase in Ruby?

  1. A. .to_lowercase
  2. B. .lower
  3. C. .downcase
  4. D. .lowercase
Report Error

What is the result of the expression: 10 / 3 in Ruby?

  1. A. 1
  2. B. 3.333
  3. C. 3
  4. D. 4
Report Error

Which operator is used for exponentiation in Ruby?

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

In Ruby, what does the 'if' statement evaluate?

  1. A. Expression
  2. B. Boolean value
  3. C. Integer
  4. D. String
Report Error

Which method is used to check if a string contains a specific substring in Ruby?

  1. A. .contains
  2. B. .exist
  3. C. .include?
  4. D. .hasSubstring
Report Error