Note
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?
Message string
Stack Backtrace
Code where the exception occurred
All of the above
puts sayGoodnight "John-Boy"
puts sayGoodnight("John-Boy")
puts(sayGoodnight "John-Boy")
puts(sayGoodnight("John-Boy"))
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
RubyStrings
Strings
Ruby
nil
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}";
The product of 5,10,15 is 750
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 Statement 1 is true. while Statement 2 is false. Statement 1 is false. while Statement 2 is true. Both the statements are true. Both the statements are false.
Statement 1 is true. while Statement 2 is false.
Statement 1 is false. while Statement 2 is true.
Both the statements are true.
Both the statements are false.
What is the output if the following code is executed at the Ruby command prompt? foo = "testing" puts defined? foo puts defined? $_
local-variable
Global-variable
testing
global-variable
None of the above
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:
Statement X is correct, while Statement Y is incorrect.
StatementX is incorrect. while Statement Y is correct
Both the statements are correct.
Both the statements are incorrect.
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?
Command 1 checks syntax only, without executing the program
Command 1 changes the directory before executing.
Command 2 checks syntax only, without executing the program.
Command 2 changes the directory before executing.
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
colors= ["Red", "Blue", "Yellow", "Green", "Violet", "Black"]for color in 0...colors.length
print colors[-color -1], "\n"
end
colors= ["Red", "Blue", "Yellow", "Green", "Violet", "Black"]
colors.each {|color| puts color}
for color in 0..colors.length
print colors[color], "\n"end
for color in 0...colors.length
print colors[color], "\n"
"retry" restarts an iteration of the most internal loop, without checking loop condition.
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?
Output of "puts method1" will be "test"
Output of "print method2" will be "test"
Output of "print method2" will be "Thisistest"
Output of "puts method1" will be nil
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]/, '*')
h'll' w‘rld
h*llo world
h’ll' world
hello w*rld
puts "Ruby String".unpack('A6')
A6
R
Ruby S
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?
This is being rescued
This is after the begin block.
This is before the raise.
This is after the raise.
This is after the begin block
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‘?
Thread.start
Thread.fork
Thread.current
Thread.join
In the following statement, what is contained in the argument 'caller'? raise InterfaceException, "Keyboard failure", caller
stack trace
string 'caller‘
Previous exception
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?
Case 1 gives a compilation error indicating that no structure is defined.
Case 2 gives an error for the "initialize" method.
Case 1 gives no error.
Case 2 gives no error.
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
1 -- Step 1
2 - Step 2
3 - Step 3
Ruby Skill Assessment
Your Skill Level: Poor
Retake Quizzes to improve it