Test Your Knowledge About Ruby Programming! Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By E.stryker
E
E.stryker
Community Contributor
Quizzes Created: 1 | Total Attempts: 2,439
Questions: 12 | Attempts: 2,444

SettingsSettingsSettings
Test Your Knowledge About Ruby Programming! Quiz - Quiz

Ruby is an Object-Oriented and interpreted scripting language which executes instructions directly and freely, without compiling a program into machine-language instructions that have similar syntaxes like another programming language for eg. C and Java. This quiz has been made to test your skills and knowledge about the basic syntax of the Ruby programming language. So, let's try out the quiz. All the best!


Questions and Answers
  • 1. 

    Ruby is what kind of programming language?

    • A.

      Strongly typed/Statically typed

    • B.

      Strongly typed/Dynamically typed

    • C.

      Weakly typed/Statically typed

    • D.

      Weakly typed/Dynamically typed

    • E.

      None of the above

    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.

    Rate this question:

  • 2. 

    The following is a primitive type in Ruby

    • A.

      Integer

    • B.

      String

    • C.

      Float

    • D.

      Char

    • E.

      None of the Above

    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

    Rate this question:

  • 3. 

    Variables that start with two '@' symbols are what kind of variables in Ruby

    • A.

      Local variable

    • B.

      Global variable

    • C.

      Instance variable

    • D.

      Class variable

    • E.

      None of the above

    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.

    Rate this question:

  • 4. 

    Variables that start with a capital letter are what kind of variables in Ruby

    • A.

      Local variable

    • B.

      Global variable

    • C.

      Instance variable

    • D.

      Class variable

    • E.

      None of the above

    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.

    Rate this question:

  • 5. 

    Variables that start a dollar sign are what kind of variables in Ruby

    • A.

      Local variable

    • B.

      Global variable

    • C.

      Instance variable

    • D.

      Class variable

    • E.

      None of the above

    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.

    Rate this question:

  • 6. 

    Ruby is an object-oriented general-purpose programming language.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Ruby allow users to manipulate data structures called objects to build and execute programs.

    Rate this question:

  • 7. 

    Which of the following is supported by Ruby?

    • A.

       Multiple Programming Paradigms

    • B.

      Dynamic Type System

    • C.

      Automatic Memory Management

    • D.

      All of the Mentioned

    Correct Answer
    D. All of the Mentioned
    Explanation
    Ruby supports all the features because it is a object oriented programming language.

    Rate this question:

  • 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}"

    • A.

      Amil Jones

    • B.

      What’s your first name? amil What’s your last name? jones My name is Amil Jones

    • C.

      What's your first name? (input) What's your last name? (input) My name is [Capitalized First Name] [Input Last Name]

    • D.

      None of the mentioned

    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.

    Rate this question:

  • 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 }."

    • 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. 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.

    Rate this question:

  • 10. 

    What does %{Learn ruby language} represents?

    • A.

      “Learn Ruby language”

    • B.

      “%{Learn Ruby language}”

    • C.

      ” Learn language ”

    • D.

      None of the mentioned

    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".

    Rate this question:

  • 11. 

    What does %x!ls! represents?

    • A.

      Same as back tick command output `ls`

    • B.

      Same as ‘x’

    • C.

      Same as “xls”

    • D.

      None of the mentioned

    Correct Answer
    A. Same as back tick command output `ls`
    Explanation
    It is same as back tick command output `ls`.

    Rate this question:

  • 12. 

    Which of the following is the valid string method?

    • A.

      The .length method

    • B.

      The .upcase method

    • C.

      The .downcase method

    • D.

      The .irreverse method

    Correct Answer
    D. The .irreverse method
    Explanation
    There is no predefined method which can reverse an already reversed string.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 08, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 28, 2007
    Quiz Created by
    E.stryker
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.