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

* lib/ostruct.rb: Add [] and []=, base on a patch by Thomas Sawyer

[ruby-core:42779] [Feature #6056]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2012-10-28 21:20:10 +00:00
parent 3785d2675a
commit e44e356b53
3 changed files with 34 additions and 8 deletions

View file

@ -70,14 +70,19 @@ class TC_OpenStruct < Test::Unit::TestCase
assert_equal(a, 'a')
end
def test_method_missing_handles_square_bracket_equals
o = OpenStruct.new
assert_raise(NoMethodError) { o[:foo] = :bar }
def test_setter
os = OpenStruct.new
os[:foo] = :bar
assert_equal :bar, os.foo
os['foo'] = :baz
assert_equal :baz, os.foo
end
def test_method_missing_handles_square_brackets
o = OpenStruct.new
assert_raise(NoMethodError) { o[:foo] }
def test_getter
os = OpenStruct.new
os.foo = :bar
assert_equal :bar, os[:foo]
assert_equal :bar, os['foo']
end
def test_to_h