Font size
WorksheetsRuby
Total questions: 80
Worksheet time: 27mins
Given the following:
MSG = "hello"
MSG.upcase!
p MSG
What is the correct result? (Choose one.)
An error occurs because MSG is a constant.
HELLO is displayed without warning.
A warning apears because MSG is a constant but HELLO is displayed
hello is displayed since MSG is a constant.
Given the following:
MSG = "hello"
MSG = MSG.upcase
p MSG
What is the correct result? (Choose one.)
An error occurs because MSG is a constant.
HELLO is displayed without warning.
A warning apears because MSG is a constant but HELLO is displayed
hello is displayed since MSG is a constant.
Which of the following can be inserted into __(1)__ in order to generate the output below? (Choose two.)
$code = "CODE"
__(1)__
puts "i like writing #{$code}"
puts "i like writing #$code"
puts 'i like writing #{$code}'
puts 'i like writing #$code'
Which of the following can be inserted into __(1)__ in order for the given code to generate the output below? (Choose two.)
puts "$foo$".__(1)__("$", "")
[Output] Foo$
sub
chop
delete
delete_prefix
Which of the following can be inserted into __(1)__ in order for the given code to generate the output below? (Choose one.)
r = "a".."e" p r.__(1)__
[Output] ["a", "b", "c", "d", "e"]
array
to_ary
to_a
to_array
Given the following:
str = "bat"
str[1,1] = "o"
p str
Which is the correct output? (Choose one.)
"boo"
"bot"
"oat"
"o"
Select the correct one as the output of the code below.
p "090-9999-0000".split('-')
["090", "9999", "0000"]
["09099990000"]
"09099990000"
"090", "9999", "0000"
Given the following:
x = "Hello" y = x.empty? ? 1 : 2
p y
Which is the correct output? (Choose one.)
1
2
"Hello"
=TRUE()
amount = 120
size = case amount
when 1..120;
"S"
when 120..170;
"M"
when 170..200;
"L"
else "XL"
end
p size
Which is the correct output? (Choose one.)
"S"
"M"
"L"
"XL"
Given the following:
s = "pear"
if s.empty?
puts "blank"
elsif s.length < 5
puts "short"
else
puts "long"
end
Which is the correct result? (Choose one.)
blank
short
long
an exception is raised
Select the correct one as the result of executing the code below.
x = 10
y = 10
unless x.eql?(y)
puts 'A'
elsif
x.equal?(y)
puts 'B'
else
puts 'C'
End
A is displayed
B is displayed as
C is displayed
I get an error
Select the correct one as the result of executing the code below.
if 0
puts "A"
elsif 0.0
puts "B"
else
puts "C"
End
A is output as
B is output as
C is output as
Exception occurs
Given the following:
m = true
m or n = true
p n
Which is the correct result? (Choose one.)
=TRUE()
=FALSE()
nil
syntax error
x = 0
4.times do |i|
x += i
end
p x
Which is the correct result? (Choose one.)
0
4
6
A syntax error occurs
Given the following:
num = 025
puts num
Which is the correct output? (Choose one.)
nil
25
21
25
Select the correct one as the output of the code below.
P 9 / 2
["090", "9999", "0000"]
1
4
4.5
Select the correct one as the output of the code below.
x = 5 * 2 ** 3
puts x
27
40
45
1000
Select the correct one as the output of the code below.
x = 10
y = 10.0
print x == y
print ','
print x.eql?(y)
true,true
true,false
false,true
false,false
Given the following:
item = "apple"
["banana", "carrot", "daikon"].each do |item|
puts item
end
puts item
Which is the correct result? (Choose one.)
A syntax error occurs
An exception is raised
banana carrot daikon Daikon
banana carrot daikon Apple
Given the following: x = 0
4.times do |i|
x += i
end
p x
Which is the correct result? (Choose one.)
0
4
6
A syntax error occurs
Given the following:
x = [1,2,3,4,5,6,7,8]
y = x
x.reject! { |e| e.even? }
p x
p y
Which is the correct output? (Choose one)
[1, 3, 5, 7] [1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 6, 7, 8] [1, 2, 3, 4, 5, 6, 7, 8]
[1, 3, 5, 7] [1, 3, 5, 7]
[1, 3, 5, 7] [2, 4, 6, 8]
Given the following:
a = [ 2, 4, 6, 8, 10 ]
a.shift
a.pop
a.push(12)
p a
Which is the correct output? (Choose one.)
[2, 4, 6, 8, 10, 12]
[2, 4, 6, 8, 10]
[4, 6, 8, 12]
[4, 6, 8]
Which of the following can be inserted into (1) in order for the given code to generate the output below? (Choose two.)
x = [ 9, 7, 5, 3, 1 ]
p __(1)__
[Output] [7, 5, 3]
X[1, 3]
X[1..-1]
X[-3..-1]
X[-4..-2]
Which of the following can be inserted into (1) in order for the given code to generate the output below? (Choose one.)
ary = [ 1, 2, 3, 4, 5 ]
p ary.__(1)__ { |i| i.odd? }
[Output] [1, 3, 5]
collect
select
map
filter
Which of the following can be inserted into __(1)__ in order for the given code to generate the output below? (Choose two.)
a = [120, 40, 20, 80, 160, 60, 180]
a.__(1)__
p a
[Output] [120, 80, 160, 180]
reject! {|i| i < 80}
reject {|i| i < 80}
delete_if! {|i| i < 80}
delete_if {|i| i < 80}
Which of the following can be inserted into __(1)__ in order for the given code to generate the output below? (Choose one.)
p ["apple", "banana"] __(1)__ ["banana", "carrot"]
[Output] ["apple", "banana", "carrot"]
.concat
&
|
||
Which of the following can be inserted into __(1)__ in order for the given code to generate the output below? (Choose two.)
p [1,16,8,4,2].__(1)__
[Output] [16, 8, 4, 2, 1]
sort_by { |x| -x }
sort_reverse
sort.reverse
reverse.sort
Select the correct one as the output of the code below.
s = "Ruby on Rails"
p s.scan(/\w/).size
1
2
11
13
Which of the following methods will NOT show you if the element :c exists in the hash key or not? (Choose one.)
h = {a: 2, b: 4, c: 6, d: 8, e: 10}
p h.has_key?(:c)
p h.contain?(:c)
p h.key?(:c)
p h.member?(:c)
Select the correct one as the output of the code below.
h = {"Ruby" => 1, "JS" => 2}
p h.size
0
1
2
4
When I ran the code below, it printed true. Please select two descriptions to fill in the blank [1] .
h = {"Ruby" => 1, "PHP" => 2}
p [1]
h.key?("PHP")
h.has_key?("PHP")
h.key_exist?("PHP")
h.include_key?("PHP")
I ran the code below and got the following output: Please select one appropriate description to fill in the blank [1]. code
h1 = {:a => 1, :b => 2, :c => 3}
h2 = h1.[1]
p h2
output {:a=>1, :c=>3}
reject { |v, k| v == 2 }
reject { |k, v| v == 2 }
delete { |v, k| v == 2 }
delete { |k, v| v == 2 }
Select the correct one as the output of the code below.
h = {"Ruby" => 1, "PHP" => 2, "C++" => 2}
p h.find { |k, v| v == 2 }
["PHP", 2]
{"PHP"=>2}
[["PHP", 2], ["C++", 2]]
{"PHP"=>2, "C++"=>2}
Select the correct one as the result of executing the code below.
h = {"Ruby" => 1, "PHP" => 2}
p h.member?("PHP")
2
=FALSE()
=TRUE()
"PHP"
I ran the code below and got the following output: Please select one appropriate description to fill in the blank [1]. code
h = {"Ruby" => 1, "JS" => 2}
p [1]
output [1, 2]
h.value
h.values
h.fetch
h.select
I ran the code below and got the following output: Please select one appropriate description to fill in the blank [1]. code
h = {"Ruby" => 1, "Perl" => 2}
p h.[1]
output ["Ruby", "Perl"]
key
keys
value
values
I ran the code below and got the following output: Please select one appropriate description to fill in the blank [1]. code
h = {"Ruby" => 1, "PHP" => 2, "C++" => 3}
p h.[1] { |k, v| k == "PHP" }
output {"PHP"=>2}
find
select
find_all
fetch
I ran the code below and got the following output: Please select one appropriate description to fill in the blank [1]. code
h = {"Ruby" => 1, "PHP" => 2, "C++" => 3}
p [1]
output [3]
h["C++"]
h.value_at("C++")
h.values_at("C++")
h.value("C++")
When I run the code below, it says "Exception". Please select one appropriate description to fill in the blanks [1] and [2].
s = "abc"
[1]
puts s - 2
[2]
puts 'Exception'
End
1 begin 2 rescue
1 catch 2throw
1 begin 2throw
1 catch 2rescue
I ran the code below and got the following output: Please select one appropriate description to fill in the blank [1]. code
arr = [1, 2, 3]
begin
puts arr.text
rescue => ex
puts ex.[1]
end
output undefined method `to_r' for [1, 2, 3]:Array
text
message
information
error_message
I ran the code below and got the following output: Please select one appropriate description to fill in the blank [1]. code
begin
puts xy + "z"
rescue [1]
puts ex.message
end
output undefined local variable or method `xy' for main:Object
StandardError >> ex
StandardError = ex
StandardError => ex
StandardError => ex
I ran the code below and got the following output: Please select one appropriate description to fill in the blank [1]. code
begin puts xy + "z"
rescue
puts "abc"
[1]
puts "xyz"
end
output: abc Xyz
ensure
else
retry
catch
Given the following:
class Object
def moo
puts "MOO!"
end
end
"Cow".moo
What is the correct result? (Choose one.)
No output.
An error occurs at run-time.
MOO!
nil
Which of the following can be inserted into __(1)__ in order for the given code to generate the output below? (Choose one.)
class Shouter
def __(1)__(message)
@message = message
end
def greet
puts @message.upcase
end
end
g = Shouter.new("Hello, world!")
g.greet
[Output] HELLO, WORLD!
Shouter
new
initialize
__init__
Which of the following can be inserted into __(1)__ in order for the given code to generate the output below? (Choose one.)
class Shouter
def initialize(message)
@message = message
end
def greet
puts @message.upcase
end
end
g = __(1)__("Hello, world!")
g.greet
[Output] HELLO, WORLD!
Shouter
#Shouter
new Shouter
Shouter.new
Given the following:
class Foo
attr_reader :var
def initialize
@var = "apple"
end
end
class Bar < Foo
def initialize
@var = "banana"
super
end
end
bar = Bar.new
puts bar.var
What is the correct result? (Choose one.)
apple
banana
No output.
An error occurs at run-time.
Select the correct one as the output of the code below.
class User
end
class Admin < User
end
print User.superclass
print ' '
print Admin.superclass
Object Object
Object User
Admin Object
Admin User
When I ran the code below, it printed 600. Please select one appropriate description to fill in the blank [1].
class Test1
def initialize(number)
@number = number * 60
end
end
class Test2 < Test1
def initialize(number)
【 1 】(number)
end
def number
@number
end
end
n = Test2.new(10)
p n.number
initialize
Test1.initialize
super
new
Select the correct one as the output of the code below.
class Test1
def initialize(number)
@number = number * 10
end
end
class Test2 < Test1
def initialize(number)
@number = number * 5
super(number)
end
def number
@number
end
end
n = Test2.new(3)
p n.number
0
3
15
30
Select the correct one as the output of the code below.
class Animal
attr_reader :name
def initialize
@name = "Hello"
end
end
class Cat < Animal
def initialize
@name = "Ruby"
end
end
a = Cat.new
p a.name
""
"Ruby"
"Hello"
nil
Given the following:
File.write("test.txt", "hellorubyworld\n")
File.open("test.txt") do |file|
file.seek(5)
print file.gets
end
Which is the correct output? (Choose one.)
hello
rubyworld
hellor
rubyw
The code below was used to open a file omitting the second argument of the open method.
In this case, which of the following is implicitly specified? (Choose one.)
file = open("sample.txt")
r
r+
a
a+
Which of the following can be inserted into __(1)__ in order for the given code to copy the content of file "test_one.txt" to file "test_two.txt"?
In the case that the “test_two.txt” file already exist, this code should set first the file size to zero and then overwrites its content from the beginning. (Choose one.)
open("test_one.txt") {|source| open("test_two.txt", "__(1)__") {|dest| dest.write(source.read) } }
r+
a
a+
w
Select the correct one as the result of executing the code below. The content of the file "sample.txt" is as follows. code
File.open("sample.txt", "a") do |io_f|
p io_f.read
end
File contents: Ruby on Rails Rails Tutorial
"Ruby on Rails\nRails Tutorial" is output as
"Ruby on Rails\n" is output as
"Ruby on Rails" is output as
Exception occurs
module Gfg
def portal
puts "Welcome to Rubyl!"
end
end
class RubyWorld
include Gfg
def add
x = 30 + 20
puts x
end
end
obj_class = RubyWorld.new
obj_class.portal
Select the correct one as the output of the code below.
nil
Welcome to Rubyl!
error occur
50
Which of the following can be inserted into __(1)__
module Gfg
def portal
puts "Welcome to Rubyl!"
end
end
class RubyWorld
_1_ Gfg
def add
x = 30 + 20
puts x
end
end
RubyWorld.portal
output: Welcome to Rubyl!
include
includes
extend
extends
module Gym
class Push
def up
puts 40
end
end
end
d = _1_.new
p d.up
output: 40
Which of the following can be inserted into __(1)__
Gym:Push
GymPush
Gym_Push
Gym::Push
module Foo1
def self.class_method_1
puts "this is class method"
end
def foo_name
puts "My name is Boo!!!"
end
end
class Bar1
include Foo1
end
Bar1.new.foo_name
Bar1.new.class_method_1
Foo1.class_method_1
Select the correct one as the output of the code below.
"My name is Boo!!!", exception raise, exception raise
exception raise, "My name is Boo!!!", , "this is class method"
"My name is Boo!!!", exception raise, "this is class method"
"My name is Boo!!!", "My name is Boo!!!", "My name is Boo!!!",
