1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-06-06 07:58:35 +00:00
parent 3c93a7d969
commit 7342e78ea6

View file

@ -101,6 +101,29 @@ class TestAssignment < Test::Unit::TestCase
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