From b127c8f72a629abae362c73128b7599f73fda3cb Mon Sep 17 00:00:00 2001 From: Loren Segal Date: Tue, 3 Sep 2024 01:27:19 -0700 Subject: [PATCH] Fix a test and optimize --- lib/yard/open_struct.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/yard/open_struct.rb b/lib/yard/open_struct.rb index d856a6b9f..4c436e2ff 100644 --- a/lib/yard/open_struct.rb +++ b/lib/yard/open_struct.rb @@ -11,10 +11,10 @@ def method_missing(name, *args) if name.to_s.end_with?('=') varname = name.to_s[0..-2].to_sym __cache_lookup__(varname) - self[varname] = args.first + send(name, args.first) else __cache_lookup__(name) - self[name] + send(name) end end @@ -60,7 +60,7 @@ def __cache_lookup__(name) key = name.to_sym.inspect instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{name}; @table[#{key}]; end - (class << self; self; end).define_method("#{name}=") { |v| @table[#{key}] = v } + def #{name.to_s.sub('?','_')}=(v); @table[#{key}] = v; end unless #{key}.to_s.include?('?') RUBY end end