- Fork this repo
- Clone your fork
- Fill in your answers by writing in the appropriate area.
- Add/Commit/Push your changes to Github.
- Open a pull request.
Note: Only place your answer between backticks. Don't modify the backticks, or the language specified after them.
What command you would use to run a script at example.rb
?
ruby example.rb
What is the alternative command to irb
you would use to run and debug Ruby in the REPL?
pry
How would you assign a star wars
variable with a value of Rogue One: A Star Wars Story
?
star_wars = Class.new
star_wars.set_name('Rogue One: A Star Wars Story')
Use string interpolation to tell the world the below character is really a Sith Lord
.
character = "Jar Jar Binks"
Write your code below:
character = "Jar Jar Binks #{@stuff}"
@stuff = "is really a Sith Lord"
What is the type of object in Ruby for decimal numbers?
float
What is the type of object in Ruby for integer numbers?
integer
Write an example of a decimal and an integer in Ruby. Replace the array values with your examples.
numbers = ["0.293948858549", "100"]
What are the values that evaluate to "falsy" in Ruby?
nil, false
Examine the following code.
batman = "Bruce Wayne"
if batman
"The Dark Knight"
else
"Just your average billionaire"
end
What will be the return value? Why?
error because the lines after the if and else are just strings and it doesnt know what to do with that.
What keyword would you use for "else if" clauses in Ruby?
elsif
Does Ruby require an explicit return from methods? Explain.
it does not require them but i believe its good practice to do so so that you know exactly what youre getting in return from your code instead of making guessses on whether or not you'll get what you think.
Instantiate a person
hash with age
and first_name
as symbols and a number age and a first name as their respective values.
Use shorthand to make this on one line.
person = {:age => 30, :first_name => "Anusone"}
How would you remove the last two elements from the below array?
arr = [12, 34, 56, 67]
Write your code below:
arr.pop(2)
Taking the result from the part 1, what are the arr
values if:
arr[arr.length + 2] = 99
Write your answer below:
arr = [12,34,nil,nil,99]
Using .each
and puts
, produce the output of the array values:
puts arr.each()
#creates a Enumerator and returns nil
puts arr
#outputs 12 34 nil nil 99 and returns nil