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

merge revision(s) 58077: [Backport #13358]

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/branches/ruby_2_3@58161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2017-03-27 15:37:55 +00:00
parent 5194682b72
commit e3defadb78
3 changed files with 14 additions and 2 deletions

View file

@ -73,7 +73,10 @@
class OpenStruct
# :nodoc:
class << self
alias allocate new
def allocate
(x = super).instance_variable_set(:@table, {})
x
end
end
#

View file

@ -181,4 +181,13 @@ class TC_OpenStruct < Test::Unit::TestCase
os.foo = 44
assert_equal(43, os.foo)
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

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.3.3"
#define RUBY_RELEASE_DATE "2017-03-28"
#define RUBY_PATCHLEVEL 270
#define RUBY_PATCHLEVEL 271
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 3