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 default return value of a method in Ruby?

  1. A. nil
  2. B. TRUE
  3. C. FALSE
  4. D. The value of the last expression
Report Error

How do you break out of a loop in Ruby?

  1. A. exit()
  2. B. break()
  3. C. continue()
  4. D. end()
Report Error

How do you check the truthiness of a value in Ruby?

  1. A. if (value) then code end
  2. B. if value do code end
  3. C. if value != false
  4. D. if value.is_truthy?
Report Error

What is the correct way to define an array in Ruby?

  1. A. array = ["element1", "element2"]
  2. B. array = Array.new
  3. C. array = new Array
  4. D. array = list("element1", "element2")
Report Error

What is the purpose of the gem command in Ruby?

  1. A. Installs and manages Ruby libraries
  2. B. Compiles Ruby code
  3. C. Runs Ruby code
  4. D. Defines Ruby classes
Report Error

What is the correct way to define a symbol in Ruby?

  1. A. symbol = "value"
  2. B. symbol = :value
  3. C. symbol = 'value'
  4. D. symbol = Symbol("value")
Report Error

What is the difference between nil and false?

  1. A. nil represents absence of value, false represents a boolean value
  2. B. Both are the same
  3. C. nil is a string, false is a boolean
  4. D. nil is a number, false is a boolean
Report Error

What is the difference between =~ and == operators?

  1. A. =~ checks for string pattern matching, == checks for equality
  2. B. =~ checks for equality, == checks for string pattern matching
  3. C. Both operators are the same
  4. D. None of the above
Report Error

What are the different types of comments in Ruby?

  1. A. Single-line // and multi-line /* */
  2. B. Single-line # and multi-line ``
  3. C. Single-line # and multi-line """ """
  4. D. Single-line // and multi-line """ """
Report Error

How do you call a method in Ruby?

  1. A. method_name()
  2. B. object.method_name
  3. C. object.method_name()
  4. D. method_name(object)
Report Error

What is the correct way to define a method in Ruby?

  1. A. def method_name(parameters) code end
  2. B. function method_name(parameters) code
  3. C. method method_name(parameters) = code
  4. D. method_name(parameters) -> code
Report Error

How do you access a value from a hash in Ruby?

  1. A. hash.get("key")
  2. B. hash["key"]
  3. C. hash.at("key")
  4. D. hash.find("key")
Report Error