Ruby

All Questions for: Ruby

Question 101: What will the following code evaluate to?

  • A None of the mentioned
  • B False
  • C Syntax error
  • D True

Explanation: The correct answer to the question is: True

Question 102: What does the notataion \b stands for?

  • A Backspace
  • B Newline
  • C Escape
  • D Space

Explanation: The correct answer to the question is: Backspace

Question 103: Which method is used to check if a string contains a specific substring in Ruby?

  • A .include?
  • B .exist
  • C .hasSubstring
  • D .contains

Explanation: The correct answer to the question is: .include?

Question 104: How do you define a range in Ruby?

  • A range = "start..end"
  • B range = Range.new("start", "end")
  • C range = start..end
  • D range = start.to(end)

Explanation: The correct answer to the question is: range = start..end

Question 105: What is the data type of the value "true" in Ruby?

  • A Float
  • B Boolean
  • C String
  • D Integer

Explanation: The correct answer to the question is: Boolean

Question 106: Which method is used to check if a variable is nil in Ruby?

  • A .empty?
  • B .is_nil?
  • C .nil?
  • D .null?

Explanation: The correct answer to the question is: .nil?

Question 107: What is the method used to check the data type of a variable in Ruby?

  • A .typeof
  • B .datatype
  • C .class
  • D .type

Explanation: The correct answer to the question is: .class

Question 108: What are the different types of comments in Ruby?

  • A Single-line // and multi-line /* */
  • B Single-line # and multi-line ``
  • C Single-line # and multi-line """ """
  • D Single-line // and multi-line """ """

Explanation: The correct answer to the question is: Single-line # and multi-line """ """

Question 109: Which of the following datatypes are valid in Ruby?

  • A All of the mentioned
  • B Numbers
  • C String
  • D Boolean

Explanation: The correct answer to the question is: All of the mentioned

Question 110: What is the method used to check if a variable is empty in Ruby?

  • A .has_content?
  • B .null?
  • C .empty?
  • D .is_empty?

Explanation: The correct answer to the question is: .empty?

Question 111: Ruby can deal with both numbers and floating point values.

  • A True
  • B False

Explanation: The correct answer to the question is: True

Question 112: What does %x!ls! represents?

  • A None of the mentioned
  • B Same as "xls"
  • C Same as back tick command output 'ls'
  • D Same as 'x'

Explanation: The correct answer to the question is: Same as back tick command output 'ls'

Question 113: What is the purpose of the gem command in Ruby?

  • A Runs Ruby code
  • B Compiles Ruby code
  • C Defines Ruby classes
  • D Installs and manages Ruby libraries

Explanation: The correct answer to the question is: Installs and manages Ruby libraries

Question 114: What is the correct syntax for defining a variable in Ruby?

  • A name = value
  • B variable name = value
  • C name: value
  • D var name = "value"

Explanation: The correct answer to the question is: name = value

Question 115: Boolean opeartors are also known as logical operators.

  • A False
  • B True

Explanation: The correct answer to the question is: True

Question 116: The == 'is equal to' is known as relational operator.

  • A False
  • B True

Explanation: The correct answer to the question is: True

Question 117: Which of the following is a valid boolean operator?

  • A All of the mentioned
  • B and(&&)
  • C not(!)
  • D or(| |)

Explanation: The correct answer to the question is: All of the mentioned

Question 118: Ruby is a case-sensitive language.

  • A True
  • B False

Explanation: The correct answer to the question is: True

Question 119: Ruby can be used for developing internet and intranet applications.

  • A True
  • B False

Explanation: The correct answer to the question is: True

Question 120: 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

Explanation: The correct answer to the question is: CONSTANT_NAME = value

Question 121: Which of the following is not a valid library function?

  • A Print
  • B Get
  • C Gets
  • D Puts

Explanation: The correct answer to the question is: Get

Question 122: What will any variable evaluate to if it is of Boolean data type?

  • A True
  • B False
  • C Either True or False
  • D Nil

Explanation: The correct answer to the question is: Either True or False

Question 123: Which of the following is the correct way to start a single-line comment in Ruby?

  • A //
  • B /*
  • C #
  • D --

Explanation: The correct answer to the question is: #

Question 124: How to comment multiple lines in ruby?

  • A All of the mentioned
  • B No option to comment
  • C Using multiline comments
  • D Using single line comments

Explanation: The correct answer to the question is: Using multiline comments

Question 125: What is the result of the expression: true && false in Ruby?

  • A TRUE
  • B FALSE
  • C Error
  • D nil

Explanation: The correct answer to the question is: FALSE

Question 126: What is the output of the expression: "hello" + "world" in Ruby?

  • A hello world
  • B hello+world
  • C "hello" "world"
  • D helloworld

Explanation: The correct answer to the question is: helloworld

Question 127: What is the method used to check if a string contains a specific substring in Ruby?

  • A .include?
  • B .contains
  • C .hasSubstring
  • D .exist

Explanation: The correct answer to the question is: .include?

Question 128: For getting an input from the user which method is used?

  • A get
  • B chomp
  • C gets.chomp
  • D get-s

Explanation: The correct answer to the question is: gets.chomp

Question 129: What is the use of .capitalize method?

  • A It capitalize the strings which are in small case
  • B It capitalizes the entire string
  • C All of the mentioned
  • D It capitalize on the first letter of the string

Explanation: The correct answer to the question is: It capitalize on the first letter of the string

Question 130: What is the correct way to declare a variable in Ruby?

  • A const name = "value"
  • B name = "value"
  • C let name = "value"
  • D var name = "value"

Explanation: The correct answer to the question is: name = "value"

Question 131: The .upcase and .capitalize method are used for capitalizing the whole string.

  • A False
  • B True

Explanation: The correct answer to the question is: False

Question 132: What does %Q{ Learn ruby language } represents?

  • A "%{ Learn Ruby language }"
  • B " Learn Ruby language "
  • C None of the mentioned
  • D " learn ruby language "

Explanation: The correct answer to the question is: " Learn Ruby language "

Question 133: What is the correct syntax for printing a message to the console?

  • A print("message")
  • B puts("message")
  • C console.log("message")
  • D write("message")

Explanation: The correct answer to the question is: puts("message")

Question 134: The following syntax is used for multiline comment.

  • A False
  • B True

Explanation: The correct answer to the question is: True

Question 135: Which of the following is not a valid datatype?

  • A Integer
  • B Binary
  • C Timedate
  • D Float

Explanation: The correct answer to the question is: Timedate

Question 136: This the right way to comment a single line.

  • A True
  • B False

Explanation: The correct answer to the question is: True

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

  • A 30
  • B Error
  • C 1010
  • D "101010"

Explanation: The correct answer to the question is: "101010"

Question 138: The given two expression means the same.

  • A False
  • B True

Explanation: The correct answer to the question is: True

Question 139: What is the correct way to define a method in Ruby?

  • A def method_name(parameters) code end
  • B function method_name(parameters) code
  • C method_name(parameters) -> code
  • D method method_name(parameters) = code

Explanation: The correct answer to the question is: def method_name(parameters) code end

Question 140: What is the method used to check if a variable is defined in Ruby?

  • A .exist?
  • B .has_value?
  • C .defined?
  • D .is_defined?

Explanation: The correct answer to the question is: .defined?

Question 141: Ruby can be embedded into Hypertext Markup Language(HTML).

  • A True
  • B False

Explanation: The correct answer to the question is: True

Question 142: What does the 'return' keyword do in Ruby methods?

  • A Exits the method with a value
  • B Converts to integer
  • C Prints to console
  • D Continues the loop

Explanation: The correct answer to the question is: Exits the method with a value

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

  • A .type_of
  • B .typeof
  • C .is_a?
  • D .class_of

Explanation: The correct answer to the question is: .is_a?

Question 144: What does %{Learn ruby language} represents?

  • A "Learn Ruby language"
  • B "%{Learn Ruby language}"
  • C None of the mentioned
  • D " Learn Ruby language "

Explanation: The correct answer to the question is: "Learn Ruby language"

Question 145: What is the result of the expression: 4 > 2 && 5 < 7 in Ruby?

  • A nil
  • B FALSE
  • C TRUE
  • D Error

Explanation: The correct answer to the question is: TRUE

Question 146: The boolean operator && only result in true when both the values are true?

  • A False
  • B True

Explanation: The correct answer to the question is: True

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

  • A .number?
  • B .numeric_value?
  • C .numeric?
  • D .is_numeric?

Explanation: The correct answer to the question is: .is_numeric?

Question 148: Assignment operator is also known as relational operator.

  • A False
  • B True

Explanation: The correct answer to the question is: True

Question 149: Why can not we use quotation marks (' or ") with boolean?

  • A It indicates that we are talking about a string
  • B It indicates that that we are replacing boolean data type with string data type
  • C None of the mentioned
  • D It indicates that we are assining a value

Explanation: The correct answer to the question is: It indicates that we are talking about a string

Question 150: Which of the following is a valid way to declare a variable in Ruby?

  • A myVar = 10
  • B 10 = myVar
  • C myVar = "10"
  • D myVar

Explanation: The correct answer to the question is: myVar = 10