CommerceBasic Syntax In Ruby MCQs
Practice Basic Syntax In Ruby MCQs for competitive exams.
Basic Syntax In Ruby MCQs
Practice questions from this topic.
Ruby is an object oriented general purpose programming language.
- A. True
- B. False
Correct Answer: A
Which of the following is not a valid datatype?
- A. Float
- B. Integer
- C. Binary
- D. Timedate
Correct Answer: D
What is the use of .capitalize method?
- A. It capitalizes the entire string
- B. It capitalize on the first letter of the string
- C. It capitalize the strings which are in small case
- D. All of the mentioned
Correct Answer: B
What is the output of the following? "Iam learning ruby language".length
- A. 26
- B. 23
- C. 20
- D. 18
Correct Answer: A
What is the output of the given code? print "what's your first name?" first_name=gets.chomp a=first_name.capitalize "first_name.capitalize!".reverse puts"My name is #{first_name}"
- A. amil jones
- B. What's your first name? amil My name is amil
- C. My name is lima
- D. My name is limA
Correct Answer: B
What is the output of the following? ruby.reverse
- A. Error in compilation
- B. ybur
- C. 4
- D. Undefined local variable ruby
Correct Answer: D
What is the output of the code? print "What's your first name?" first_name=gets.chomp a=first_name.capitalize first_name.capitalize! print "What's your last name?" last_name=gets.chomp b=last_name.capitalize last_name.capitalize puts "My name is #{first_name} #{last_name}"
- A. Amil Jones
- B. What's your first name? amil What's your last name? jones My name is Amil Jones
- C. My name is Amil jones
- D. None of the mentioned
Correct Answer: B
What is the output of given code? string="I'am Learning RUBY Language".downcase string.upcase
- A. Undefined method
- B. "I'AM LEARNING RUBY LANGUAGE"
- C. I'am Learning RUBY Language
- D. None of the mentioned
Correct Answer: B
What will be the output of the given code? "Come let's learn.reverse Ruby.length language".upcase
- A. nreal s'tel emoC 4 LANGUAGE
- B. Undefined error
- C. "COME LET'S LEARN.REVERSE RUBY.LENGTH LANGUAGE"
- D. None of the above
Correct Answer: C
How to comment multiple lines in ruby?
- A. Using multiline comments
- B. Using single line comments
- C. No option to comment
- D. All of the mentioned
Correct Answer: A
Why do we use comments?
- A. For later use to understand the working of the program
- B. It is an efficient way of programming
- C. It makes easy for the third person to understand
- D. All of the mentioned
Correct Answer: D
What will be the output of the given code? "I'am learning Ruby Language".reverse.upcase.length
- A. 27
- B. egaugnal ybuR gninreal ma'I
- C. ERAUGNAL YBUR GNINREAL MA'I
- D. Undefined method 'reverse' for 27:Fixnum
Correct Answer: A