CSE 3901 MIDTERM FULL REVISION NOTES
WITH GIT, VERSION CONTROL, AND WEB
DEVELOPMENT CONCEPTS
◉ 1.
Answer: ruby: what does "cab" <=> "ba" return?
◉ i = 34, j = 35.
Answer: i = 34
j = i # i and j are aliases
j = j + 1 # does this increment i too?
what is the value of i and j?
◉ prints 0 to 24.
Answer: what does the following statement do?
i = 10
25.times { | i | puts i }
◉ "tania".length.
Answer: ruby: write a statement that returns the length of your
name
,◉ "exam".reverse.
Answer: ruby: write a statement that reverses the word "exam"
◉ puts "Tania".upcase.
Answer: ruby: write a statement that prints "Tania" in uppercase
◉ puts "Tania".downcase.
Answer: ruby: write a statement that prints "Tania" in lowercase
◉ puts "What is your first name?"
name = gets.chomp
puts "Your first name is #{name.capitalize!}".
Answer: ruby: write a statement that asks for the users first name
and prints the result in the following format: Your first name is
(name). The name should be capitalized
◉ for i in 1..20
next if i % 2 != 0
puts i
end.
,Answer: ruby: write a for loop that prints all even numbers between
1 and 20
◉ num = 1
until num > 10
puts num
num += 1
end.
Answer: ruby: write a looping using until that prints numbers 1 to
20
◉ Start of method
In the block
In the block
End of method.
Answer: What does the following code output?
def call_block
puts 'Start of method'
yield
yield
puts 'End of method'
end
, call_block {puts 'In the block'}
◉ equal? : Checks if the object id is the same (reference value)
eql? : True if the receiver and argument have both the same type and
equal values (same hash key).
=== : tests range inclusion
== : Checks if the value of two operands are equal or not.
Answer: What's the difference between equal?, eql?, ===, and == ?
◉ 10^20.
Answer: a = 10
b = 20
What is the return value for a**b?
◉ position = "cat o' 9 tails" =~ /a/
puts position.
Answer: write a statement that prints the index of the first
occurrence of 'a' in the string "cat o' 9 tails"
WITH GIT, VERSION CONTROL, AND WEB
DEVELOPMENT CONCEPTS
◉ 1.
Answer: ruby: what does "cab" <=> "ba" return?
◉ i = 34, j = 35.
Answer: i = 34
j = i # i and j are aliases
j = j + 1 # does this increment i too?
what is the value of i and j?
◉ prints 0 to 24.
Answer: what does the following statement do?
i = 10
25.times { | i | puts i }
◉ "tania".length.
Answer: ruby: write a statement that returns the length of your
name
,◉ "exam".reverse.
Answer: ruby: write a statement that reverses the word "exam"
◉ puts "Tania".upcase.
Answer: ruby: write a statement that prints "Tania" in uppercase
◉ puts "Tania".downcase.
Answer: ruby: write a statement that prints "Tania" in lowercase
◉ puts "What is your first name?"
name = gets.chomp
puts "Your first name is #{name.capitalize!}".
Answer: ruby: write a statement that asks for the users first name
and prints the result in the following format: Your first name is
(name). The name should be capitalized
◉ for i in 1..20
next if i % 2 != 0
puts i
end.
,Answer: ruby: write a for loop that prints all even numbers between
1 and 20
◉ num = 1
until num > 10
puts num
num += 1
end.
Answer: ruby: write a looping using until that prints numbers 1 to
20
◉ Start of method
In the block
In the block
End of method.
Answer: What does the following code output?
def call_block
puts 'Start of method'
yield
yield
puts 'End of method'
end
, call_block {puts 'In the block'}
◉ equal? : Checks if the object id is the same (reference value)
eql? : True if the receiver and argument have both the same type and
equal values (same hash key).
=== : tests range inclusion
== : Checks if the value of two operands are equal or not.
Answer: What's the difference between equal?, eql?, ===, and == ?
◉ 10^20.
Answer: a = 10
b = 20
What is the return value for a**b?
◉ position = "cat o' 9 tails" =~ /a/
puts position.
Answer: write a statement that prints the index of the first
occurrence of 'a' in the string "cat o' 9 tails"