Ruby Assessment

Email your answers to: alex.grant@generalassemb.ly

Question 1

a = 2
b = 3
a = b

At the end of this program, what are the values of a and b? Try to explain, in plain English, how you got your answer for each one.

Question 2

c = 5
d = 2
c = c + d

At the end of this program, what is the value of c?
Try to explain, in plain English, what the last line of this program (c = c + d) means.

Question 3

e = 4
f = 6
g = e + f
e = 1

At the end of this program, what are the values of e, f, and g? Try to explain, in plain English, how you got your answer for each one.

Question 4

x = 4
y = 3
x = y
y = 10

At the end of this program, what are the values of x and y? Try to explain, in plain English, how you got your answer for each one.

Question 5

Imagine that you take the code from Question 4, save it to a file called test.rb, and run ruby test.rb in your Terminal.

What would be the output? Explain your answer.

Question 6

weather = "sunny"
weather == "sunny" 

What is the difference between these two statements? Explain your answer.

Question 7

x = 4

if x == 3
	puts "sushi is tasty"
end

if x > 0
	puts "sushi is delicious"
end

Imagine that you take the code from this question, save it to a file called food.rb, and run ruby food.rb in your Terminal.

What would be the output? Explain your answer.

Question 8

x = 3

if x == 3
	puts "sushi is tasty"
elsif x > 0
	puts "sushi is delicious"
end

Imagine that you take the code from this question, save it to a file called sushi.rb, and run ruby sushi.rb in your Terminal.

What would be the output? Explain your answer.

Question 9

x = 2

if x > 0
	puts "Chuck Norris can do a wheelie on a unicycle"
	x = x + 1
end

puts x

Imagine that you take the code from this question, save it to a file called huzzah.rb, and run ruby huzzah.rb in your Terminal.

What would be the output? Explain your answer.

Question 10

kitty = "lolcat"

if kitty == "lolcat"
	puts "i can has cheezburger?"
else 
	puts "im in ur code fixin ur bugz"
end

Imagine that you take the code from this question, save it to a file called kitty.rb, and run ruby kitty.rb in your Terminal.

What would be the output? Explain your answer.

Question 11

fruit = "tomato"

if fruit == "banana"
	puts "yum"
end

Imagine that you take the code from this question, save it to a file called kitty.rb, and run ruby kitty.rb in your Terminal.

What would be the output? Explain your answer.

Question 12

What is the value of fruit at the end of the code in Question 11? Try to explain, in plain English, how you got your answer.

Question 13

wizard = "harry potter"

if wizard
	puts "alohomora"
end

Imagine that you take the code from this question, save it to a file called spell.rb, and run ruby spell.rb in your Terminal.

What would be the output? Explain your answer.

Question 14

x = 9/10

puts x
puts x.to_i
puts x.to_f

Imagine that you take the code from this question, save it to a file called numbers.rb, and run ruby numbers.rb in your Terminal.

What would be the output? Explain your answer.

Terminal/Bash Questions

Question 15

What command outputs my current directory?

Question 16

What command outputs a listing of all files and directories in the current directory?

Question 17

How can I change to my home directory?

Question 18

How can I rename the file named question.txt to answer.txt?

Question 19

How can I delete a directory named wrong within my current directory, including all its contents and subdirectories?

Question 20

How can I allow it so that anyone can read, write and execute the file called virus.sh?