ruby-changes:34283
From: nobu <ko1@a...>
Date: Fri, 6 Jun 2014 16:58:49 +0900 (JST)
Subject: [ruby-changes:34283] nobu:r46364 (trunk): test_assignment.rb: assignment to private attribute
nobu 2014-06-06 16:58:35 +0900 (Fri, 06 Jun 2014) New Revision: 46364 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46364 Log: test_assignment.rb: assignment to private attribute * test/ruby/test_assignment.rb (test_assign_private_self): test for r3509, assignment to private attribute is allowed iff its receiver is literal `self`. Modified files: trunk/test/ruby/test_assignment.rb Index: test/ruby/test_assignment.rb =================================================================== --- test/ruby/test_assignment.rb (revision 46363) +++ test/ruby/test_assignment.rb (revision 46364) @@ -101,6 +101,29 @@ class TestAssignment < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_assignment.rb#L101 assert_equal([1, 2, 3, [1, 2, 3]], a[:x], bug2050) end + def test_assign_private_self + o = Object.new + class << o + private + def foo=(a); 42; end + def []=(i, a); 42; end + end + + assert_raise(NoMethodError) { + o.instance_eval {o.foo = 1} + } + assert_nothing_raised(NoMethodError) { + assert_equal(1, o.instance_eval {self.foo = 1}) + } + + assert_raise(NoMethodError) { + o.instance_eval {o[0] = 1} + } + assert_nothing_raised(NoMethodError) { + assert_equal(1, o.instance_eval {self[0] = 1}) + } + end + def test_yield def f; yield(nil); end; f {|a| assert_nil(a)}; undef f def f; yield(1); end; f {|a| assert_equal(1, a)}; undef f -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/