diff options
author | Marc-Andre Lafortune <[email protected]> | 2020-09-14 13:48:29 -0400 |
---|---|---|
committer | Marc-André Lafortune <[email protected]> | 2020-09-14 16:10:37 -0400 |
commit | 606c009ce24bd8e9e07ecb8f920a77c005062ff5 (patch) | |
tree | ce09e8c5a70da914079172c4b89f00577bf9be8d /lib/ostruct.rb | |
parent | 67e5f7a9e508d6f33c1dd927753161e8b1d40a09 (diff) |
[ruby/ostruct] Avoid self calling our public methods.
Found because `json` has a bad example in its test suite.
This implementation still offers better encapsulation.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3541
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r-- | lib/ostruct.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb index d674274966..9b44d4a88a 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -124,7 +124,7 @@ class OpenStruct @table = {} if hash hash.each_pair do |k, v| - self[k] = v + set_ostruct_member_value!(k, v) end end end @@ -218,7 +218,7 @@ class OpenStruct if len != 1 raise ArgumentError, "wrong number of arguments (given #{len}, expected 1)", caller(1) end - self[mname]= args[0] + set_ostruct_member_value!(mname, args[0]) elsif len == 0 elsif @table.key?(mid) raise ArgumentError, "wrong number of arguments (given #{len}, expected 0)" @@ -262,6 +262,8 @@ class OpenStruct new_ostruct_member!(name) @table[name] = value end + alias_method :set_ostruct_member_value!, :[]= + private :set_ostruct_member_value! # :call-seq: # ostruct.dig(name, *identifiers) -> object |