From: marcandre-ruby-core@... Date: 2020-09-08T21:48:10+00:00 Subject: [ruby-core:99971] [Ruby master Bug#15409] OpenStruct error when attribute is called 'method' Issue #15409 has been updated by marcandre (Marc-Andre Lafortune). I opened a PR that resolves this: https://github.com/ruby/ostruct/pull/15 Note that using a field called `:method` has never worked with `OpenStruct` before; only private methods could be overridden. The PR does a few things: - reverts lazy initialization and restores overriding private methods - allows overriding public methods (as in this issue, for flexibility and compatibility with `Struct`) - creates aliases ending with `!` for public instance methods (e.g. `OpenStruct.new.class! # => OpenStruct`) - adds documentation about the caveats of using `OpenStruct` and recommending not using it at all - small refactoring to better handle frozen state ---------------------------------------- Bug #15409: OpenStruct error when attribute is called 'method' https://bugs.ruby-lang.org/issues/15409#change-87510 * Author: elioncho (El�as Orozco) * Status: Assigned * Priority: Normal * Assignee: marcandre (Marc-Andre Lafortune) * ruby -v: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- The following error is shown when you try to access an OpenStruct with a property called method: `method': wrong number of arguments (given 0, expected 1) (ArgumentError) To replicate: ~~~ ruby require 'ostruct' o = OpenStruct.new({ method: 'get' }) o.method ~~~ The expected behavior should be to return 'get' -- https://bugs.ruby-lang.org/ Unsubscribe: