Consider the following statements regarding range operators in Ruby:
Statement X: The two.dot form. "..’. range operator creates a range from start point to end point inclusive.
Statement Y: The three-dot form. "...", range operator creates a range from start point to end point exclusive.
Correct Answer:
Both the statements are correct.
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
+
-
\
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
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.
Correct Answer:
Statement 1 is true. while Statement 2 is false.
Note: This Question is unanswered, help us to find answer for this one
What is the purpose of the following array method in Ruby?
array.rassoc(key)
Correct Answer:
it searches through the array whose elements are also arrays.
Note: This Question is unanswered, help us to find answer for this one
What is the output of the following code. when executed at the Ruby command prompt?
puts "This is sentence 1."
BEGIN {
puts "This is sentence 2."
}
Correct Answer:
This is sentence 2. This is sentence 1.
Note: This Question is unanswered, help us to find answer for this one
What is the purpose of the following hash method in Ruby?
hash.rehash
Correct Answer:
it rebuilds hash based on the current values for each key.
Note: This Question is unanswered, help us to find answer for this one
What is the output of the Ruby code (with line numbers) shown below?
1. (0...5).each do |i|
2. puts "Value of local variable is #{i}"
3. end
Correct Answer:
Value of local variable is 0 Value of local variable is 1 Value of local variable is 2 Value of local variable is 3 Value of local variable is 4
Note: This Question is unanswered, help us to find answer for this one
What is the output of the following two lines of codes executed at the Ruby command prompt?
puts 'escape the sentence using "\\"'
puts 'That\'s right, this is a test'
Correct Answer:
escape the sentence using "\" That's right, this is a test
Note: This Question is unanswered, help us to find answer for this one
What is the output of the following code, when executed at the Ruby command prompt?
print <<EOF
This is a sample text
EOF
print <<"EOF";
This is a sample text too
EOF
Correct Answer:
This is a sample text This is a sample text too
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
if "Rick".index("c") >> 2
if -1942.abs >> 1942
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
DBD::Mysql implements some driver-specific functions to be used In Ruby. Given below is one such function:
dbh.func(:insert_id) => Fixnum
What is the purpose of this function?
Correct Answer:
It returns the most recent AUTO_lNCREMENT value for a connection.
Note: This Question is unanswered, help us to find answer for this one
Consider the following statements regarding environment variables in Ruby:
Statement 1: Environment variable "RUBYLIB" defines the search path for libraries.
Statement 2: Environment variable "RUBYLIB_PREFIX" modifies the
"RUBYLIB" search path by replacing the prefix of a particular library.
Correct Answer:
Both the statements are correct.
Note: This Question is unanswered, help us to find answer for this one
What is the output of the following code in Ruby?
a = "hello world"
puts a.scan(/(..)(..)/)
Correct Answer:
he ll o wo
Note: This Question is unanswered, help us to find answer for this one
Given below is a Ruby code snippet with line numbers:
Note: A file named "test" is located at the location "/var/www/ruby/"
1. aFile = File.new("/var/www/ruby/test", "r")
2. if aFile
3. aFile.syswrite("RUBY Testing")
4. print "Done!"
5. else
6. puts "Unable to open file!"
7. end
What is the outcome when the above code is executed?
Correct Answer:
It gives an error on line number 3.
Note: This Question is unanswered, help us to find answer for this one
What is the purpose of the following hash method in Ruby?
hash.to_a
Correct Answer:
It creates a two-dimensional array from hash. Each key/'value pair is converted to an array. and all these arrays are stored in a containing array.
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
U Catch defines a block that is labeled with the given name.
Ll When Ruby encounters a throw. it zips back the call stack looking for a catch block with a matching symbol.
D it the input does not contain correctly formatted lines. the throw will skip to the end of the corresponding catch.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
In the Ruby programming language, "true" is a type of :
Correct Answer:
Pseudo variable
Note: This Question is unanswered, help us to find answer for this one
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?
Correct Answer:
irb(main):001:0> "hello"[2]<br>
=> "e"
Note: This Question is unanswered, help us to find answer for this one
What is the output of the following code?
$debug=56
print "Sample Text\n" if $debug
Correct Answer:
Sample Text
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
Ruby identifier names may consist of alphanumeric characters and the underscore character ( _ ).
'rescue' is a reserved word in RUBY, but it can be used as a method name.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
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
Correct Answer:
1 -- Step 1 3 - Step 3
Note: This Question is unanswered, help us to find answer for this one
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?
Correct Answer:
Case 2 gives an error for the "initialize" method.
Case 1 gives no error.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
In the following statement, what is contained in the argument 'caller'?
raise InterfaceException, "Keyboard failure", caller
Correct Answer:
stack trace
Note: This Question is unanswered, help us to find answer for this one
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‘?
Correct Answer:
Thread.start Thread.fork
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
LJ Ruby is a true object-oriented programming language.
D Ruby can be used to write Common Gateway interface (CGI) scripts.
Ci Ruby can be installed in both Windows and POSIX environments.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
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?
Correct Answer:
This is before the raise. This is being rescued This is after the begin block.
Note: This Question is unanswered, help us to find answer for this one
What is the output of the following code in Ruby?
puts "Ruby String".unpack('A6')
Correct Answer:
Ruby S
Note: This Question is unanswered, help us to find answer for this one
What is the output of the following code in Ruby?
puts "hello world".sub(/[aeiou]/, '*')
Correct Answer:
h*llo world
Note: This Question is unanswered, help us to find answer for this one
Which of the following statements regarding ".eql?" and ".equal?" are correct?
Correct Answer:
.equal? returns true it the receiver and argument have the same object id.
.eqi? returns true if the receiver and argument have both the same type and equal values.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
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?
Correct Answer:
Output of "puts method1" will be "test" Output of "print method2" will be "Thisistest"
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
"redo" restarts an iteration of the most internal loop, without checking loop condition.
“retry" restarts the invocation of an iterator call. Also. arguments to the iterator are re-evaluated.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
x + y =15
x -y = 5
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
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
Correct Answer:
colors= ["Red", "Blue", "Yellow", "Green", "Violet", "Black"] colors.each {|color| puts color} colors= ["Red", "Blue", "Yellow", "Green", "Violet", "Black"] for color in 0...colors.length print colors[color], "\n" end
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
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?
Correct Answer:
Command 1 checks syntax only, without executing the program Command 2 changes the directory before executing.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
f.path returns the pathname used to create f.
f.chmod(mode) changes the permission mode of f.
Note: This question has more than 1 correct answers
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
undef
Note: This Question is unanswered, help us to find answer for this one
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:
Correct Answer:
StatementX is incorrect. while Statement Y is correct
Note: This Question is unanswered, help us to find answer for this one
What is the output if the following code is executed at the Ruby command prompt?
foo = "testing"
puts defined? foo
puts defined? $_
Correct Answer:
testing global-variable
Note: This Question is unanswered, help us to find answer for this one
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
Correct Answer:
Statement 1 is true. while Statement 2 is false.
Note: This Question is unanswered, help us to find answer for this one
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}";
Correct Answer:
The product of 5,10,15 is 750
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
it starts an interactive Ruby Session.
Note: This Question is unanswered, help us to find answer for this one
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
Correct Answer:
RubyStrings RubyStrings RubyStrings
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
All of the above
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
Statement 1 is true, while Statement 2 is false.
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
Pseudo variable
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
Statement 1 is true, while Statement 2 is false.
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
h*llo world
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
irb(main):001:0> "hello"[2]<br>
=> "e"
Note: This Question is unanswered, help us to find answer for this one
Ruby MCQs | Topic-wise