1.
Ruby is what kind of programming language?
Correct Answer
B. Strongly typed/Dynamically typed
Explanation
Ruby is a programming language that is strongly typed, meaning that it enforces strict type checking, and dynamically typed, meaning that variable types are determined at runtime rather than during compilation. In Ruby, variables can hold values of any type and can be reassigned to different types, allowing for flexibility in programming.
2.
The following is a primitive type in Ruby
Correct Answer
E. None of the Above
Explanation
A primitive type is a type that is not an object; i.e. it does not inherit from the Object class
3.
Variables that start with two '@' symbols are what kind of variables in Ruby
Correct Answer
D. Class variable
Explanation
Variables that start with two '@' symbols in Ruby are class variables. Class variables are shared among all instances of a class and can be accessed and modified by any instance of the class. They are defined within the class but outside of any method or constructor.
4.
Variables that start with a capital letter are what kind of variables in Ruby
Correct Answer
E. None of the above
Explanation
In Ruby, variables that start with a capital letter are considered constants. Constants are variables whose value cannot be changed once assigned. They are typically used to represent values that are not meant to be modified throughout the program. Therefore, the correct answer is "None of the above" as the given options (local variable, global variable, instance variable, and class variable) do not include constants.
5.
Variables that start a dollar sign are what kind of variables in Ruby
Correct Answer
B. Global variable
Explanation
In Ruby, variables that start with a dollar sign ($) are considered global variables. Global variables can be accessed and modified from anywhere in the program, making them accessible across different scopes and classes. This means that any changes made to a global variable in one part of the program will affect its value in other parts of the program as well.
6.
Ruby is an object-oriented general-purpose programming language.
Correct Answer
A. True
Explanation
Ruby allow users to manipulate data structures called objects to build and execute programs.
7.
Which of the following is supported by Ruby?
Correct Answer
D. All of the Mentioned
Explanation
Ruby supports all the features because it is a object oriented programming language.
8.
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}"
Correct Answer
C. What's your first name? (input) What's your last name? (input) My name is [Capitalized First Name] [Input Last Name]
Explanation
The code prompts the user to enter their first name and stores it in the variable first_name.
It capitalizes the first letter of the first name using .capitalize method and stores it in variable a.
It then capitalizes the first letter of the first name in place using capitalize!.
Next, the code prompts the user to enter their last name and stores it in the variable last_name.
It capitalizes the first letter of the last name using .capitalize method and stores it in variable b.
However, the capitalize method on last_name is not applied in place, so the last name remains unchanged.
Finally, it prints out the message with #{first_name} and #{last_name}, where first_name and last_name are both capitalized due to previous modifications.
9.
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 }."
Correct Answer
C. The value of x is 12.
The sum of x and y is 48.
The average was 40.
Explanation
x, y, z assigned the values 12, 36, 72 and then arithmetic operations performed on them.
10.
What does %{Learn ruby language} represents?
Correct Answer
A. “Learn Ruby language”
Explanation
In Ruby, %{...} is a way to delimit a string, similar to single or double quotes. It allows for string interpolation and can contain any characters, including spaces and special characters. Therefore, %{Learn Ruby language} represents the string "Learn Ruby language".
11.
What does %x!ls! represents?
Correct Answer
A. Same as back tick command output `ls`
Explanation
It is same as back tick command output `ls`.
12.
Which of the following is the valid string method?
Correct Answer
D. The .irreverse method
Explanation
There is no predefined method which can reverse an already reversed string.