mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
ostruct.rb: fix OpenStruct.allocate
* lib/ostruct.rb (OpenStruct.allocate): initialize an instance variable directly, without calling `intialize` method which may be overridden in a subclass. [ruby-core:80292] [Bug #13358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7142f5b595
commit
cd911b9367
2 changed files with 13 additions and 1 deletions
|
@ -74,7 +74,10 @@
|
||||||
#
|
#
|
||||||
class OpenStruct
|
class OpenStruct
|
||||||
class << self # :nodoc:
|
class << self # :nodoc:
|
||||||
alias allocate new
|
def allocate
|
||||||
|
(x = super).instance_variable_set(:@table, {})
|
||||||
|
x
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -183,4 +183,13 @@ class TC_OpenStruct < Test::Unit::TestCase
|
||||||
os.foo = 44
|
os.foo = 44
|
||||||
assert_equal(43, os.foo)
|
assert_equal(43, os.foo)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_allocate_subclass
|
||||||
|
bug = '[ruby-core:80292] [Bug #13358] allocate should not call initialize'
|
||||||
|
c = Class.new(OpenStruct) {
|
||||||
|
def initialize(x,y={})super(y);end
|
||||||
|
}
|
||||||
|
os = assert_nothing_raised(ArgumentError, bug) {c.allocate}
|
||||||
|
assert_instance_of(c, os)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue