diff --git a/lib/ostruct.rb b/lib/ostruct.rb index 417ecf62b3..1d42321b66 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -71,9 +71,6 @@ # 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 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: diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index 7df5200ca1..b9bbaace55 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -183,4 +183,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 diff --git a/version.h b/version.h index 3731e5bf2c..e95ed8a70f 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #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