Use define_method instead

This commit is contained in:
Douglas Eichelberger 2023-12-31 11:29:57 -08:00
parent ffd761d2e9
commit db97ff2dce

View File

@ -14,19 +14,9 @@ module Attrable
sig { params(attrs: Symbol).void } sig { params(attrs: Symbol).void }
def attr_rw(*attrs) def attr_rw(*attrs)
attrs.each do |attr| attrs.each do |attr|
module_eval <<-EOS, __FILE__, __LINE__+1 define_method attr do |val = nil|
def #{attr}(val=nil) # def prefix(val=nil) val.nil? ? instance_variable_get(:"@#{attr}") : instance_variable_set(:"@#{attr}", val)
if val.nil? # if val.nil? end
if instance_variable_defined?(:@#{attr}) # if instance_variable_defined?(:@prefix)
return @#{attr} # return @prefix
else # else
return nil # return nil
end # end
end # end
#
@#{attr} = val # @prefix = val
end # end
EOS
end end
end end
end end