Skip to content

Instantly share code, notes, and snippets.

@mmower
Created September 20, 2009 15:19
Show Gist options
  • Save mmower/189822 to your computer and use it in GitHub Desktop.
Save mmower/189822 to your computer and use it in GitHub Desktop.
x = "test"
y = " string"
z = x + y
puts"#{x} + #{y} = #{z}"
require 'test/unit'
class TestInterpolation < Test::Unit::TestCase
def test_basic
assert_equal(z = "test string", z ="test string")
end
end
##
# Okay you need to think more carefully about what you are doing here.
#
# The expression
#
# z = 'test string'
#
# will assign 'test string' to z, then evaluate to 'test string'
#
# What that means is that you are, effectively, setting z to test string, but
# also comparing something to itself which, in this context, must always be true
#
# So
assert_equal 'test string', z
or, if you are just testing that interpolation isn't broken somehow
assert_equal 'test string', "#{"test" + " string"}"
would work just as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment