Skip to content

Commit

Permalink
test_assignment.rb: assignment to private attribute
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Jun 6, 2014
1 parent 3c93a7d commit 7342e78
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/ruby/test_assignment.rb
Expand Up @@ -101,6 +101,29 @@ def test_assign_abbreviated
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
Expand Down

0 comments on commit 7342e78

Please sign in to comment.