CommerceBasic 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?
- A. until
- B. loop
- C. while
- D. repeat
Correct Answer: A
What is the output of the expression: "hello" + "world" in Ruby?
- A. helloworld
- B. hello world
- C. hello+world
- D. "hello" "world"
Correct Answer: A
Which method is used to find the length of an array in Ruby?
- A. .size
- B. .length
- C. .count
- D. .length_of
Correct Answer: B
What is the correct syntax for a multiline comment in Ruby?
- A. /* ... */
- B. // ... //
- C. ''' ... '''
- D. # ... #
Correct Answer: C
Which of the following is the correct way to define a range in Ruby?
- A. (1..10)
- B. [1 to 10]
- C. {1..10}
Correct Answer: A
In Ruby, what is the correct way to define a constant?
- A. constant_name = value
- B. constant name : value
- C. CONSTANT_NAME = value
- D. constant_name(value)
Correct Answer: C
What does the 'return' keyword do in Ruby methods?
- A. Exits the method with a value
- B. Prints to console
- C. Converts to integer
- D. Continues the loop
Correct Answer: A
Which method is used to convert a string to lowercase in Ruby?
- A. .to_lowercase
- B. .lower
- C. .downcase
- D. .lowercase
Correct Answer: C
What is the result of the expression: 10 / 3 in Ruby?
- A. 1
- B. 3.333
- C. 3
- D. 4
Correct Answer: C
Which operator is used for exponentiation in Ruby?
- A. **
- B. ^
- C. ^^
- D. //
Correct Answer: A
In Ruby, what does the 'if' statement evaluate?
- A. Expression
- B. Boolean value
- C. Integer
- D. String
Correct Answer: B
Which method is used to check if a string contains a specific substring in Ruby?
- A. .contains
- B. .exist
- C. .include?
- D. .hasSubstring
Correct Answer: C