Skip to content

Instantly share code, notes, and snippets.

@igaiga
Created April 25, 2014 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igaiga/11278955 to your computer and use it in GitHub Desktop.
Save igaiga/11278955 to your computer and use it in GitHub Desktop.
test_unit
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
@igaiga
Copy link
Author

igaiga commented Apr 25, 2014

変数xが共有されているかと思って「スコープ???」と思ってたのだけど、単に @objが参照する先のArrayオブジェクトを破壊的に変更していただけだった。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment