CommerceBasic 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?
- A. var name = "value"
- B. variable name = value
- C. name = value
- D. name: value
Correct Answer: C
Which of the following is NOT a valid data type in Ruby?
- A. Integer
- B. Float
- C. Double
- D. String
Correct Answer: C
What does the 'gets' method do in Ruby?
- A. Prints to console
- B. Converts to string
- C. Reads input from user
- D. Finds the length
Correct Answer: C
Which of the following is a valid variable name in Ruby?
- A. my_variable
- B. 123variable
- C. _variable
- D. variable-1
Correct Answer: A
In Ruby, what is the keyword used to define a method?
- A. function
- B. define
- C. method
- D. def
Correct Answer: D
What does the 'puts' method do in Ruby?
- A. Prints to console
- B. Converts to string
- C. Finds the length
- D. Reads input from user
Correct Answer: A
Which symbol is used to concatenate strings in Ruby?
- A. +
- B. .
- C. :
- D. <<
Correct Answer: D
What symbol is used to denote comments in Ruby?
- A. //
- B. #
- C. --
- D. /* */
Correct Answer: B