Test Your Knowledge About Ruby Programming! Quiz

Approved & Edited by ProProfs Editorial Team
At ProProfs Quizzes, our dedicated in-house team of experts takes pride in their work. With a sharp eye for detail, they meticulously review each quiz. This ensures that every quiz, taken by over 100 million users, meets our standards of accuracy, clarity, and engagement.
Learn about Our Editorial Process
| Written by E.stryker
E
E.stryker
Community Contributor
Quizzes Created: 1 | Total Attempts: 2,352
Questions: 12 | Attempts: 2,354

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? amil What’s your last name? jones My name is Amil jones

    • D. 

      None of the mentioned

    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.

    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 Ruby language ”

    • D. 

      None of the mentioned

    Correct Answer
    A. “Learn Ruby language”
    Explanation
    Anything written inside %{} is same as anything written inside “”.

    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:

Back to Top Back to top
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.