Project

General

Profile

Bug #17512 ยป 0001-Allow-ostruct-to-return-a-value-on-super.patch

ostruct super patch - HParker (Adam Hess), 01/05/2021 08:22 PM

View differences:

lib/ostruct.rb
239 239
        raise! ArgumentError, "wrong number of arguments (given #{len}, expected 1)", caller(1)
240 240
      end
241 241
      set_ostruct_member_value!(mname, args[0])
242
    elsif len == 0
242
    elsif len == 0 # and /\A[a-z_]\w*\z/ =~ mid #
243
      if @table.key?(mid)
244
        new_ostruct_member!(mid) unless frozen?
245
        @table[mid]
246
      end
243 247
    else
244 248
      begin
245 249
        super
test/ostruct/test_ostruct.rb
249 249
    assert_equal(:bar, os.format)
250 250
  end
251 251

  
252
  def test_super
253
    c = Class.new(OpenStruct) {
254
      def foo; super; end
255
    }
256
    os = c.new(foo: :bar)
257
    assert_equal(:bar, os.foo)
258
  end
259
  
252 260
  def test_overridden_public_methods
253 261
    os = OpenStruct.new(method: :foo, class: :bar)
254 262
    assert_equal(:foo, os.method)