ruby-changes:47292
From: nagachika <ko1@a...>
Date: Sun, 23 Jul 2017 17:39:54 +0900 (JST)
Subject: [ruby-changes:47292] nagachika:r59407 (ruby_2_4): merge revision(s) 58077, 58229: [Backport #13358]
nagachika 2017-07-23 17:39:46 +0900 (Sun, 23 Jul 2017) New Revision: 59407 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59407 Log: merge revision(s) 58077,58229: [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] ostruct.rb: improve fix for OpenStruct.allocate + #respond_to? * lib/ostruct.rb (OpenStruct#respond_to_missing?): this makes OpenStruct#respond_to? works on any OpenStruct instance, just like Kernel#respond_to? does, without workarounds. [ruby-core:80292] [Bug #13358] Modified directories: branches/ruby_2_4/ Modified files: branches/ruby_2_4/lib/ostruct.rb branches/ruby_2_4/test/ostruct/test_ostruct.rb branches/ruby_2_4/version.h Index: ruby_2_4/lib/ostruct.rb =================================================================== --- ruby_2_4/lib/ostruct.rb (revision 59406) +++ ruby_2_4/lib/ostruct.rb (revision 59407) @@ -71,9 +71,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/ostruct.rb#L71 # of these properties compared to using a Hash or a Struct. # class OpenStruct - class << self # :nodoc: - alias allocate new - end # # Creates a new OpenStruct object. By default, the resulting OpenStruct @@ -191,7 +188,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/ostruct.rb#L188 def respond_to_missing?(mid, include_private = false) mname = mid.to_s.chomp("=").to_sym - @table.key?(mname) || super + @table&.key?(mname) || super end def method_missing(mid, *args) # :nodoc: Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 59406) +++ ruby_2_4/version.h (revision 59407) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.2" #define RUBY_RELEASE_DATE "2017-07-23" -#define RUBY_PATCHLEVEL 158 +#define RUBY_PATCHLEVEL 159 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 7 Index: ruby_2_4/test/ostruct/test_ostruct.rb =================================================================== --- ruby_2_4/test/ostruct/test_ostruct.rb (revision 59406) +++ ruby_2_4/test/ostruct/test_ostruct.rb (revision 59407) @@ -183,4 +183,13 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ostruct/test_ostruct.rb#L183 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 Index: ruby_2_4 =================================================================== --- ruby_2_4 (revision 59406) +++ ruby_2_4 (revision 59407) Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r58077,58229 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/