Ruby Programming Quiz

26 Questions | Total Attempts: 203

SettingsSettingsSettings
Please wait...
Programming Quizzes & Trivia

Developed in 1995, Ruby is an object-oriented programming language that is dynamic, reflective and general-purpose. What do you know about the ins and outs of the language? Let’s take a look in this programming-themed quiz!


Questions and Answers
  • 1. 
    In Ruby, the difference between using double quotes and single quotes to make a string, is
    • A. 

      Single quotes will ignore any variables it finds with #{}, while double quotes will replace the variables it finds with #{}

    • B. 

      Double quotes will ignore any variables it finds with #{}, while single quotes will replace the variables it finds with #{}

    • C. 

      Single quotes will ignore any variables it finds with #{''}, while double quotes will replace the variables it finds with #{''}

    • D. 

      Double quotes will ignore any variables it finds with #{''}, while Single quotes will replace the variables it finds with #{''}

  • 2. 
    In Ruby, the order of operations for numeric variables follows the acronym ..... where A is Addition,D is Division,E is Exponent, M is Multiplication,P is Parenthesis, S is Subtraction
    • A. 

      Left to Right, irrespective of what the operation is

    • B. 

      Parenthesis(P) first and then Left to Right, irrespective of what the operation is

    • C. 

      PEDMAS

    • D. 

      PEMDAS

  • 3. 
    The string method in ruby that helps remove trailing newline character from a string str is
    • A. 

      Str.chop

    • B. 

      Str.chomp

    • C. 

      Str.each_line

    • D. 

      Str.slice

  • 4. 
    The right way to copy an array a to b is
    • A. 

      Clone

    • B. 

      B = a.collect

    • C. 

      B = a.copy

    • D. 

      Use the each method with a do block to copy each element

  • 5. 
    ______________________  Returns the operating system’s temporary file path.
    • A. 

      Dir()

    • B. 

      Tmpdir()

    • C. 

      Tempfile()

    • D. 

      Tempdir()

  • 6. 
    Instance variables need not be declared
    • A. 

      True

    • B. 

      False

  • 7. 
    • A. 

      Scope of the instance variable is restricted to the object self refers to

    • B. 

      Scope of instance variables is limited to the class in which the variable is instantiated

    • C. 

      Instance variables are always public variables

    • D. 

      Instance variables can be used as constants in a program

  • 8. 
    Instance variables in ruby are prefixed by _____ symbol
    • A. 

      @

    • B. 

      #

    • C. 

      ~

    • D. 

      ^

  • 9. 
    The ________________ method removes all duplicates and retains all distinct elements in an array.
    • A. 

      Uniq

    • B. 

      Unique

    • C. 

      Distinct

    • D. 

      One

  • 10. 
    In Ruby, the stream that reads from a file passed via command line is called
    • A. 

      ARGF

    • B. 

      ARGV

    • C. 

      STDIN

    • D. 

      -n flag

  • 11. 
    The ruby method to trim all leading trailing whitespaces is
    • A. 

      Strip()

    • B. 

      Trim()

    • C. 

      Chomp()

    • D. 

      Chop()

  • 12. 
    In ruby, By convention, the names of procedures that store values into previously allocated locations  usually end in 
    • A. 

      !

    • B. 

      []

    • C. 

      ()

    • D. 

      ?

  • 13. 
    Provide a ruby function using gsub and regex to delete all whitespaces in a string str
  • 14. 
    If ASCII for A = '65', then "AAAA".unpack('C') returns
    • A. 

      [65]

    • B. 

      [65, 65, 65, 65]

    • C. 

      [65, nil, 65, nil, nil]

    • D. 

      14

  • 15. 
    ___________________ calls a block for each item and returns a new array based on the results of the block.
    • A. 

      Array.map

    • B. 

      Array.select

    • C. 

      Array.each

    • D. 

      Array.each_with_index

  • 16. 
    The command to check the syntax of a ruby file named test.rb is
  • 17. 
    In ruby, to convert a string str to uppercase
    • A. 

      Str.upcase

    • B. 

      Str.uppercase

    • C. 

      Str.upper

    • D. 

      Str.UPPER

  • 18. 
    In ruby, to convert a string str to lowercase
    • A. 

      Str.downcase

    • B. 

      Str.lower

    • C. 

      Str.lowercase

    • D. 

      Str.lcase

  • 19. 
    In ruby,y = 'str'puts 'Test, #{y}'results in
    • A. 

      Test, #{y}

    • B. 

      Test, str

    • C. 

      Test, y

    • D. 

      Test,

  • 20. 
    In ruby, !!0
    • A. 

      True

    • B. 

      False

    • C. 

      Nil

    • D. 

      0

  • 21. 
    In ruby, !!nil means
    • A. 

      True

    • B. 

      False

    • C. 

      Nil

    • D. 

      0

  • 22. 
    'Lorem ipsum dolor sit ame'  =~ /ip/
    • A. 

      0

    • B. 

      Nil

    • C. 

      True

    • D. 

      6

  • 23. 
    'Lorem ipsum dolor sit ame'  =~ /L/
    • A. 

      0

    • B. 

      Nil

    • C. 

      True

    • D. 

      1

  • 24. 
    'Lorem ipsum dolor sit ame'  = ~  /fg/   #  =>
    • A. 

      0

    • B. 

      Nil

    • C. 

      True

    • D. 

      False

  • 25. 
    'Lorem ipsum dolor sit ame'  ! ~  /fg/   #  =>
    • A. 

      0

    • B. 

      True

    • C. 

      Nil

    • D. 

      False

  • 26. 
    The three major types of variables in ruby are
    • A. 

      Local(_), Instance($) and Static($$)

    • B. 

      Bool, Char & Float

    • C. 

      Class (@@), Instance (@) and Global($)

    • D. 

      There is no restriction on variable type in ruby