Bug #4179 ยป ostruct_square_bracket_equals.patch
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
|