Sha256: 2b9ab421b701510854707cf28026906a9c1add5432c4cbf83caf02b4b8cd95e8

Contents?: true

Size: 795 Bytes

Versions: 7

Compression:

Stored size: 795 Bytes

Contents

class Module
  def mattr_reader(*syms)
    syms.each do |sym|
      next if sym.is_a?(Hash)
      class_eval(<<-EOS, __FILE__, __LINE__)
        unless defined? @@#{sym}
          @@#{sym} = nil
        end
        
        def self.#{sym}
          @@#{sym}
        end

        def #{sym}
          @@#{sym}
        end
      EOS
    end
  end
  
  def mattr_writer(*syms)
    syms.each do |sym|
      class_eval(<<-EOS, __FILE__, __LINE__)
        unless defined? @@#{sym}
          @@#{sym} = nil
        end
        
        def self.#{sym}=(obj)
          @@#{sym} = obj
        end
        
        #{"
        def #{sym}=(obj)
          @@#{sym} = obj
        end
        "}
      EOS
    end
  end
  
  def mattr_accessor(*syms)
    mattr_reader(*syms)
    mattr_writer(*syms)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rawler-0.1.0 lib/rawler/core_extensions/module.rb
rawler-0.0.9 lib/rawler/core_extensions/module.rb
rawler-0.0.8 lib/rawler/core_extensions/module.rb
rawler-0.0.7 lib/rawler/core_extensions/module.rb
rawler-0.0.6 lib/rawler/core_extensions/module.rb
rawler-0.0.5 lib/rawler/core_extensions/module.rb
rawler-0.0.4 lib/rawler/core_extensions/module.rb