Ruby Quiz # 1

Instructions
Quiz: Ruby Quiz # 1
Subject: Basic Ruby
Total Questions: 52 MCQs
Time: 52 Minutes

Note

  • Do not refresh the page while taking the test.
  • Results along with correct answers will be shown at the end of the test.
Ruby Quiz # 1
Question 1 of 52
00:00
  • Consider the following Interactive Ruby Shell console quotes. In one of the quotes, => is not the real irb result.
    Which of the following is that quote?


  • What is the output of the following code in Ruby?

    puts "hello world".sub(/[aeiou]/, '*')


  • Read the following statements and select the correct option.

    Statement 1: When a Ruby program terminates, all running threads are killed, regardless of their states.
    Statement 2: You can wait for a particular thread to finish by calling that thread's Thread#wait method.


  • In the Ruby programming language, "true" is a type of :

  • Read the following statements and select the correct option.

    Statement 1: A thread shares all global, instance, and local variables that are in existence at the time the thread starts.
    Statement 2: Ruby threads are totally out-of-process, and are implemented outside the Ruby interpreter.


  • The package that contains information about an exception is an object of class exception or is one of class exception's children . Every exception returns information to understand the nature of the exception. Which of the following are provided by exceptions?

  • Which of the following are correct?

  • What is the output of the following code in Ruby?

    x= "Ruby" + "Strings"

    puts x

    y= "Ruby" << "Strings"

    puts y

    z = "Ruby".concat("Strings")

    puts z


  • In a Ruby installed environment, what happens when "lrb" is typed in the command prompt?

  • What is the output of the following line of code executed at the Ruby command prompt?

    puts "The product of 5,10,15 is #{5*10*15}";

  • Read the following statements and select the correct option.

    Statement 1: When a Ruby program terminates, all running threads are killed. regardless of their states.

    Statement 2: You can wait for a particular thread to finish by calling that thread

  • What is the output if the following code is executed at the Ruby command prompt?

    foo = "testing"
    puts defined? foo
    puts defined? $_


  • Consider the following statements regarding "methods" in Ruby

    Statement X: Method names should begin with an uppercase letter.

    Statement Y: Methods should be defined before calling them, otherwise Ruby will raise an exception for undefined method invoking.

    Select an appropriate option from below:


  • Which of the following is used to cancel the method definition?

  • Assuming that f is an instance of the File class:

  • Consider the following two commands issued at the Ruby command prompt:
    Command 1: $ ruby -c
    Command 2: $ ruby -C dir
    Which of the following statements regarding these two commands are correct?

  • Consider an array "colors" which has the following contents:
    colors= ["Red", "Blue", "Yellow", "Green", "Violet", "Black"]
    Which of the given options will print the following output?
    Red
    Blue
    Yellow
    Green
    Violet
    Black

  • if there are two variables x and y, such that x=10 and y=5, then:

  • What is the difference between “redo" and "retry" statements in Ruby?

  • The following code snippet has two methods, namely "method1" and "method2".
    def method1
       x = "This"
       y = "is"
       z = "test"
    end
    puts method1
    def method2
       x = "This"
       y = "is"
       z = "test"
      return x, y, z
    end
    print method2
    What will be the output of the method1 and method2 when called with puts and print?

  • Which of the following statements regarding ".eql?" and ".equal?" are correct?

  • What is the output of the following code in Ruby?
    puts "hello world".sub(/[aeiou]/, '*')

  • What is the output of the following code in Ruby?

    puts "Ruby String".unpack('A6')

  • Given below is a Ruby code demonstrating Exception Handling with begin/end block, and rescue clauses.
    begin
        puts 'This is before the raise.'
        raise 'Raising an Error'
        puts 'This is after the raise.'
    rescue
        puts 'This is being rescued'
    end
    puts 'This is after the begin block.'

    What is the output the above code?

  • Which of the following statements regarding Ruby are correct?

  • Ruby makes it easy to write multi-threaded programs with the Thread class. Ruby threads are a lightweight and efficient way to achieve parallelism in the code. Which of the following calls have the same functionality as “Threadnew‘?

  • In the following statement, what is contained in the argument 'caller'?
    raise InterfaceException, "Keyboard failure", caller

  • Given below are two different cases of class definition, and object instantiation in Ruby.
    Case 1:
    -----------
    class Demo
    end
      p = Demo.new
    Case 2:
    ---------
    class Demo2
      def initialize(x,y)
        @x, @y = x, y
      end
    end
      p = Demo2.initialize(15,20)
    What happens when both these cases are executed separately?

  • What is the output of the following code?
    $var = 1
    print "1 -- Step 1\n" if $var
    print "2 -- Step 2\n" unless $var
    $var = false
    print "3 -- Step 3\n" unless $var

  • Which of the following statements regarding the Ruby programming language are correct?

Ruby Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

Ruby Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it