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
B. What’s your first name? amil
What’s your last name? jones
My name is Amil Jones
Explanation
Capitalize method was not called at the time of last name, jones was not printed correctly it was not modified because ! was not used.
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
Anything written inside %{} is same as anything written inside “”.
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.