Computer

Data Types And Variables In Ruby MCQs

Practice Data Types And Variables In Ruby MCQs for competitive exams.

Data Types And Variables In Ruby MCQs

Practice questions from this topic.

What is the output of the expression: 7 / 2 in Ruby?

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

In Ruby, what is the default file extension for Ruby files?

  1. A. .ru
  2. B. .rby
  3. C. .rb
  4. D. .ruby
Report Error

What is the correct way to declare and initialize an array in Ruby?

  1. A. array_name = []
  2. B. array array_name = []
  3. C. array_name = array[]
  4. D. array = array_name[]
Report Error

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

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

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

  1. A. 1
  2. B. 1.33
  3. C. 3
  4. D. 0
Report Error

What is the method 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

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

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

What is the method used to check if a variable is of a specific class in Ruby?

  1. A. .is_a?
  2. B. .type_of
  3. C. .typeof
  4. D. .class_of
Report Error

Which method is used to convert a string to an array of characters in Ruby?

  1. A. .to_chars
  2. B. .split
  3. C. .to_array
  4. D. .chars
Report Error

What is the output of the expression: "10" * 3 in Ruby?

  1. A. "101010"
  2. B. 30
  3. C. 1010
  4. D. Error
Report Error

What is the method used to check if a variable is numeric in Ruby?

  1. A. .numeric?
  2. B. .is_numeric?
  3. C. .number?
  4. D. .numeric_value?
Report Error

Which of the following is the correct way to declare a variable in Ruby with a default value?

  1. A. var_name = value
  2. B. var_name := value
  3. C. var_name << value
  4. D. var_name => value
Report Error