From: ruby-core@... Date: 2018-12-13T06:59:43+00:00 Subject: [ruby-core:90495] [Ruby trunk Bug#15409] OpenStruct error when attribute is called 'method' Issue #15409 has been updated by marcandre (Marc-Andre Lafortune). I don't have a good solution. `OpenStruct` is kind of an anti-pattern. This is even more apparent when adding methods to `Object/Kernel`. I note that `Struct` allows overriding builtin methods: Struct.new(:method, keyword_init: true).new(method: :foo).method # => :foo I'd be tempted to allow overriding of methods in `OpenStruct` for setters (e.g. `method=`), but not very confident about it. Even if we allow overriding like this, this could still yield to potentially unexpected results. o = OpenStruct.new o.then # => nil in Ruby 2.5, Enumerator in Ruby 2.6 o.then = :foo # (assuming we allow overriding from setters) o.then # => :foo If the object is inited with the data like `OpenStruct.new(then: :foo)`, then both versions would at least behave the same. ---------------------------------------- Bug #15409: OpenStruct error when attribute is called 'method' https://bugs.ruby-lang.org/issues/15409#change-75652 * Author: elioncho (El��as Orozco) * Status: Assigned * Priority: Normal * Assignee: marcandre (Marc-Andre Lafortune) * Target version: * 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: