Class: Module

Inherits:
Object
  • Object
show all
Defined in:
extend/module.rb

Instance Method Summary collapse

Instance Method Details

#attr_rw(*attrs) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'extend/module.rb', line 5

def attr_rw(*attrs)
  attrs.each do |attr|
    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