17 lines
472 B
Ruby
Raw Normal View History

2021-09-11 01:00:23 +01:00
# typed: true
# frozen_string_literal: true
class Module
def attr_rw(*attrs)
attrs.each do |attr|
2021-01-29 09:11:35 +00:00
module_eval <<-EOS, __FILE__, __LINE__+1
def #{attr}(val=nil) # def prefix(val=nil)
@#{attr} ||= nil # @prefix ||= nil
return @#{attr} if val.nil? # return @prefix if val.nil?
@#{attr} = val # @prefix = val
end # end
EOS
end
end
end