Project

General

Profile

Bug #4179 ยป ostruct_square_bracket_equals.patch

Test case for []= and [], and fix for []= bug - caius (Caius Durling), 12/21/2010 08:40 AM

View differences:

lib/ostruct.rb
def method_missing(mid, *args) # :nodoc:
mname = mid.id2name
len = args.length
if mname.chomp!('=')
if mname.chomp!('=') && mname != "[]"
if len != 1
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
end
test/ostruct/test_ostruct.rb
assert_raise(TypeError) {o.a = 'z'}
assert_equal('a', o.a)
end
def test_method_missing_handles_square_bracket_equals
o = OpenStruct.new
assert_raise(NoMethodError) { o[:foo] = :bar }
end
def test_method_missing_handles_square_brackets
o = OpenStruct.new
assert_raise(NoMethodError) { o[:foo] }
end
end
    (1-1/1)