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 output of the given code? print "What's your first name?" first_name=gets.chomp a=first_name.capitalize a=a.reverse puts"My name is #{a}"
- A. amil jones
- B. What's your first name? amil My name is Amil
- C. What's your first name? amil My name is limA
- D. My name is limA
Correct Answer: B
What is the output of the given code? x, y, z = 12, 36, 72 puts "The value of x is #{ x }." puts "The sum of x and y is #{ x + y }." puts "The average was #{ (x + y + z)/3 }."
- A. 12,48,40
- B. Syntax error
- C. The value of x is 12. The sum of x and y is 48. The average was 40.
- D. None of the mentioned
Correct Answer: C
Why do we use =begin and =end?
- A. To mark the start and end of multiline comment
- B. To comment multiple lines
- C. To avoid the use of # again and again
- D. All of the mentioned
Correct Answer: D
Which of the following type of comments are valid in ruby?
- A. Single line comments
- B. Multi line comments
- C. Double line comments
- D. All of the mentioned
Correct Answer: D
What is the range of octal notation (nnn)?
- A. 0-8
- B. 0-7
- C. 0-A
- D. None of the mentioned
Correct Answer: B
What will be the output of the given code? "I'am learning Ruby Language".length.reverse.upcase
- A. 27
- B. egaugnal ybuR gninreal ma'I
- C. ERAUGNAL YBUR GNINREAL MA'I
- D. Undefined method 'reverse' for 27:Fixnum
Correct Answer: D
What is the role of ! at the end of the capitalize method?
- A. It is the syntax for using capitalize method
- B. It modifies the value stored in the variable
- C. It indicates the termination of string
- D. None of the mentioned
Correct Answer: B
Which of the following are valid floating point literal?
- A. .5
- B. 2
- C. 0.5
- D. None of the mentioned
Correct Answer: C
What will be the output of the following? "Ruby".reverse.upcase
- A. RUBY
- B. ybuR
- C. YBUR
- D. YBUr
Correct Answer: C
Ruby is a case-sensitive language.
- A. True
- B. False
Correct Answer: A
Why is the library function 'puts'used for?
- A. Prints whatever is given and print it to the screen
- B. Prints whatever is given and insert a new(blank) line
- C. Gets input from the user
- D. None of the mentioned
Correct Answer: B
It is must for Ruby to use a compiler.
- A. True
- B. False
Correct Answer: B