Created
April 25, 2014 05:55
-
-
Save igaiga/11278955 to your computer and use it in GitHub Desktop.
test_unit
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
require "test/unit" | |
class TestFoo < Test::Unit::TestCase | |
def test_foo | |
@obj = [[1,2],[3,4]] | |
assert_equal([[1, 2, "a"], [3, 4, "a"]], | |
@obj.map {|x| x << "a" }) | |
proc = Proc.new {|x| x << "b" } | |
assert_equal([[1, 2, "a", "b"], [3, 4, "a", "b"]], | |
@obj.map(&proc)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
変数xが共有されているかと思って「スコープ???」と思ってたのだけど、単に @objが参照する先のArrayオブジェクトを破壊的に変更していただけだった。