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.
Read more...........
- 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.
- defined
- undef
- self
- rescue
puts “Ruby String”.unpack(‘A6′)
- A6
- Ruby
- R
- Ruby S
- Local variables begin with a lowercase letter or _.
- Instance variables are preceded by the at sign (@) followed by the variable name.
- Class variables are preceded by the sign @@ and are followed by the variable name.
- Global variables are always preceded by the # character.
array.rassoc(key)
- It searches through the array whose elements are also arrays.
- It returns a new array containing the items array for which the block is not true.
- It returns the number of non-nil elements in self.
- %m represents minute of the hour (00 to 59).
- %I represents hour of the day, 12-hour clock (01 to 12).
- %A represents the abbreviated weekday name (Sun).
- %j represents the day of the year (001 to 366).
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?
- It gives an error on line number 2.
- No error is generated, and it prints “Done”.
- It gives an error on line number 3.
- It gives an error on line number 1.
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.
- Statement X is incorrect, while Statement Y is correct.
- Both the statements are correct.
- Both the statements are incorrect.
- Catch defines a block that is labeled with the given name.
- The catch block is executed normally even if a throw is encountered.
- When Ruby encounters a throw, it zips back the call stack looking for a catch block with a matching symbol.
- If the input does not contain correctly formatted lines, the throw will skip to the end of the corresponding catch.
Which of the following is that quote?
- irb(main):001:0> “gin joint”.length
=> 9 - irb(main):001:0> “hello”[2]
=> “e” - irb(main):001:0> “Rick”.index(“c”)
=> 2 - irb(main):001:0> “e”*3
=> “eee” - None of the above
puts ‘escape the sentence using “\\”‘;
puts ‘That\’s right, this is a test';
- escape the sentence using “\”
That’s right, this is a test - escape the sentence using “\\”
That’s right, this is a test - escape the sentence using “\”
That\’s right, this is a test - escape the sentence using “\”
Thats right, this is a test
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.
- Statement X is correct, while Statement Y is incorrect.
- Statement X is incorrect, while Statement Y is correct.
- Both the statements are correct.
- Both the statements are incorrect.
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 respective methods when called?
- 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
- Message string
- Stack Backtrace
- Code where the exception occurred
- All of the above
- Only integers
- Only string objects
- Any type of object
- An integer or a string object
- Ruby is a true object-oriented programming language.
- Ruby can be used to write Common Gateway Interface (CGI) scripts.
- Ruby cannot be embedded into Hypertext Markup Language (HTML).
- Ruby can be installed in both Windows and POSIX environments.
foo = “testing”
puts defined? foo
puts defined? $_
puts defined? foo2
- local-variable
global-variable
nil - testing
global-variable
not defined - testing
nil
nil - local-variable
global-variable
not defined
- f.path returns the pathname used to create f.
- f.ctime returns the last access time for f.
- f.chmode(mode) changes the permission mode of f.
- f.mtime returns the last inode change time for f.
puts “hello world”.sub(/[aeiou]/, ‘*’)
- h*ll* w*rld
- h*llo world
- h*ll* world
- hello w*rld
$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 - 1 — Step 1
3 — Step 3 - 1 — Step 1
2 — Step 2 - 1 — Step 1
nil
nil
- x + y =15
- x – y = 5
- x % y = 2
- x ** y = 250
- Instance variable
- Pseudo variable
- Class variable
- Constant
raise InterfaceException, “Keyboard failure”, caller
- stack trace
- string ‘caller’
- Previous exception
- None of the above
- puts sayGoodnight “John-Boy”
- puts sayGoodnight(“John-Boy”)
- puts(sayGoodnight “John-Boy”)
- puts(sayGoodnight(“John-Boy”))
- All of the above
- Thread.start
- Thread.fork
- Thread.current
- Thread.join
hash.rehash
- It rebuilds hash based on the current values for each key.
- It returns hash (self).
- It creates a new hash, inverting keys and values from hash. That is, in the new hash, keys from hash become values, and values become keys.
- It tests whether hash is empty, returning true or false.
- d.rewind moves the position in d to the first entry.
- d.tell returns the current position in d.
- d.read returns the current entry from d.
- d.close closes the directory stream.
dbh.func(:insert_id) => Fixnum
What is the purpose of this function?
- It returns the protocol being used for the communication.
- It returns the current thread ID.
- It returns the most recent AUTO_INCREMENT value for a connection.
- It returns the current state of the database.
$debug=56
print “Sample Text\n” if $debug
- 56
- Sample Text
- No output
- An Error is given
- “gin joint”.length >> 9
- “Rick”.index(“c”) >> 2
- -1942.abs >> 1942
- number = Math.abs(number)
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.
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.
- 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.
- Ruby identifiers are case insensitive.
- 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.
puts “This is sentence 1.”
BEGIN {
puts “This is sentence 2.”
}
- This is sentence 2.
This is sentence 1. - This is sentence 1.
This is sentence 2. - This is sentence 1.This is sentence 2.
- The code will give a syntax error.
- ;
- +
- -
- \
x= “Ruby” + “Strings”
puts x
y= “Ruby” << “Strings”
puts y
z = “Ruby”.concat(“Strings”)
puts z
- RubyStrings
RubyStrings
RubyStrings - RubyStrings
Strings
RubyStrings - RubyStrings
Ruby
nil - RubyStrings
nil
RubyStrings
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.
- Statement 1 is correct, while Statement 2 is incorrect.
- Statement 2 is correct, while Statement 1 is incorrect.
- Both the statements are correct.
- Both the statements are incorrect.
print <<EOF
This is a sample text
EOF
print <<“EOF”;
This is a sample text too
EOF
- This is a sample text
This is a sample text too - This is a sample text
This is a sample text too - This is a sample textThis is a sample text too
- The code gives a syntax error.
- .eql? returns true if the receiver and argument have the same object id.
- .equal? returns true if the receiver and argument have the same object id.
- .eql? returns true if the receiver and argument have both the same type and equal values.
- .equal? returns true if the receiver and argument have both the same type and equal values.
- It starts an Interactive Ruby Session.
- It enables parser debug mode.
- It displays an overview of command-line options.
- It overwrites the file contents with program output.
puts “The product of 5,10,15 is #{5*10*15}”;
- 750
- The product of 5,10,15 is 750
- The product of 5,10,15 is #{5*10*15}
- It will give typecasting error.
1. (0…5).each do |i|
2. puts “Value of local variable is #{i}”
3. end
- 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
Value of local variable is 5 - Value of local variable is 1
Value of local variable is 2
Value of local variable is 3
Value of local variable is 4 - 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 - The code gives an error on line number “1”
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.
hash.to_a
- 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.
- It returns a new array containing all the values of hash.
- It returns a new array containing the values from hash that are associated with the given key or keys.
- It converts hash to an array, and then converts that array to a string.
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. - This is before the raise.
This is being rescued
This is after the begin block.
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} - colors= [“Red”, “Blue”, “Yellow”, “Green”, “Violet”, “Black”]
for color in 0..colors.length
print colors[color], “\n”;
end - colors= [“Red”, “Blue”, “Yellow”, “Green”, “Violet”, “Black”]
for color in 0…colors.length
print colors[color], “\n”;
end
- “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.
- “redo” restarts the invocation of an iterator call. Also, arguments to the iterator are re-evaluated.
- “retry” restarts an iteration of the most internal loop, without checking loop condition.
a = “hello world”
puts a.scan(/(..)(..)/)
- he
ll
o
wo - [[“he”, “ll”], [“o “, “wo”]]
- hello
world - [“hello”, “world”]
- f.path returns the pathname used to create f.
- f.ctime returns the last access time for f.
- f.chmod(mode) changes the permission mode of f.
- f.mtime returns the last inode change time for f.
foo = “testing”
puts defined? foo
puts defined? $_
- local-variable
global-variable - testing
global-variable - testing
nil - None of the above
print <<EOF
This is a sample text
EOF
print <<“EOF”;
This is a sample text too
EOF
- This is a sample text
This is a sample text too - This is a sample text
This is a sample text too - This is a sample textThis is a sample text too
- The code gives a syntax error.
puts “This is sentence 1.”
BEGIN {
puts “This is sentence 2.”
}
- This is sentence 2.
This is sentence 1. - This is sentence 1.
This is sentence 2. - This is sentence 1.This is sentence 2.
- The code will give a syntax error.
$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 - 1 — Step 1
3 — Step 3 - 1 — Step 1
2 — Step 2 - 1 — Step 1
nil
nil
Which of the following is that quote
- irb(main):001:0> “gin joint”.length
=> 9 - irb(main):001:0> “hello”[2]
=> “e” - irb(main):001:0> “Rick”.index(“c”)
=> 2 - irb(main):001:0> “e”*3
=> “eee” - None of the above
x= “Ruby” + “Strings”
puts x
y= “Ruby” << “Strings”
puts y
z = “Ruby”.concat(“Strings”)
puts z
- RubyStrings
RubyStrings
RubyStrings - RubyStrings
Strings
RubyStrings - RubyStrings
Ruby
nil - RubyStrings
nil
RubyStrings
1. (0…5).each do |i|
2. puts “Value of local variable is #{i}”
3. end
- 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
Value of local variable is 5 - Value of local variable is 1
Value of local variable is 2
Value of local variable is 3
Value of local variable is 4 - 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 - The code gives an error on line number “1”
- “gin joint”.length >> 9
- “Rick”.index(“c”) >> 2
- -1942.abs >> 1942
- number = Math.abs(number)
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. - This is before the raise.
This is being rescued
This is after the begin block.
a. = “hello world”
puts a.scan(/(..)(..)/)
a.he
ll
o
wo
- [[“he”, “ll”], [“o “, “wo”]]
- hello
world - [“hello”, “world”]
foo = “testing”
puts defined? foo
puts defined? $_
- local-variable
global-variable - testing
global-variable - testing
nil - None of the above
No comments:
Post a Comment