Skip to content

Commit f3f0ca4

Browse files
committed
Override #singleton_methods and #methods
This is done only for strict backward compatibility. It may not be needed for practical backward compatibility.
1 parent 930b547 commit f3f0ca4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/ostruct.rb

+23
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,29 @@ def freeze
271271
super
272272
end
273273

274+
def singleton_methods(*) # :nodoc:
275+
(super + @table.keys.flat_map {|k| [k, :"#{k}="] }).uniq
276+
end
277+
278+
def methods(*) # :nodoc:
279+
(super + @table.keys.flat_map {|k| [k, :"#{k}="] }).uniq
280+
end
281+
282+
def respond_to_missing?(mid, *) # :nodoc:
283+
if (mname = mid[/.*(?==\z)/m])
284+
@table&.key?(mname.to_sym)
285+
elsif @table&.key?(mid)
286+
true
287+
else
288+
begin
289+
super
290+
rescue NoMethodError => err
291+
err.backtrace.shift
292+
raise!
293+
end
294+
end
295+
end
296+
274297
private def method_missing(mid, *args) # :nodoc:
275298
len = args.length
276299
if mname = mid[/.*(?==\z)/m]

0 commit comments

Comments
 (0)