Skip to content

Instantly share code, notes, and snippets.

@pricees
Last active August 29, 2015 13:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pricees/9102552 to your computer and use it in GitHub Desktop.
Save pricees/9102552 to your computer and use it in GitHub Desktop.
My Ruby Litmus Test.rb
# Integer vs Float div by zero gotchas
#
#
1 / 0 = [answer]
1.0 / 0 = [answer]
1 / 0.0 = [answer]
0 / 0.0 = [answer]
# String concatenation vs interpolation
x = 5
"Num = #{x}" # Whats the output and why?
"Num = " + x # whats the output and why?
# Arrays
[1,2,3,4 ... 1,000] # return all the evens
# Modules vs Classes: Questions
#
# What are some differences between a module and a class?
# What are the two canonical uses for modules?
# What are your 2 favorite methods in Enumerable?
# Whats the difference between extend and include?
# Bonus: What is the name of the include hook method?
# What are the differences between a string and a symbol?
# Bonus: Why might a symbol be used as a hash key?
# Bonus * 2: How long does a symbol stay in memory?
# Use the following code ./person.rb
class Person
def salutation
"Hello"
end
end
# Write an initializer to satisfy these tests
Person.new.salutation == "Hello"
Person.new("Bonjour").salutation == "Bonjour"
Person.new("Hola").salutation == "Hola"
# Make this test pass
Person.new.salutation == "Gutan Tag"
# Without opening the class make this test pass
Person.new.good_bye == "Laters!"
# Bonus Questions which stopped being asked
# Given: [1,2,3].inject(:+) == 6, how does this work?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment