Created
October 25, 2016 16:18
-
-
Save booty/354e4ee3e2208a7a977fc7c22fe063e3 to your computer and use it in GitHub Desktop.
I ran this under 2.3 and was confused.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class YourMom | |
def speak | |
msg = "You'll be late for school! It's #{Time.now}" | |
puts msg | |
puts "...object id was #{msg.object_id}" | |
msg2 = "Eat your vegetables!" | |
puts msg2 | |
puts "...object id was #{msg2.object_id}" | |
end | |
end | |
# Works. The interpolated strings aren't frozen, but the | |
# the "Eat your vegetables" is | |
mom = YourMom.new | |
mom.speak | |
sleep 2 | |
mom.speak | |
puts " ~~~~~~~~~~~~~ " | |
# Doesn't work - string is interpolated, then frozen. | |
# Returns the same time + object_id the second time | |
msg = "Thanks for finally showing up to school. It's currently #{Time.now}" | |
puts msg | |
puts "...object id was #{msg.object_id}" | |
sleep 2 | |
puts msg | |
puts "...object id was #{msg.object_id}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment