Sha256: b2224102ea44a7b23d1ce58e5fbabd006a7191bd7b1d46a09c74cbe58c557551

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

Contents

module Conglomerate
  module MixinIvarHelper
    def self.included(klass)
      klass.send(:extend, ClassMethods)
    end

    private

    module ClassMethods
      def mc_ivar_writer(*names)
        names.each do |name|
          self.send(:define_singleton_method, "#{name}=") do |val|
            instance_variable_set("@#{name}", val)
          end
        end
      end

      def mc_ivar_reader(*names)
        names.each do |name|
          self.send(:define_singleton_method,name) do
            instance_variable_get("@#{name}")
          end
        end
      end

      def mi_ivar_writer(*names)
        names.each do |name|
          self.send(:define_method, "#{name}=") do |val|
            instance_variable_set("@#{name}", val)
          end
        end
      end

      def mi_ivar_reader(*names)
        names.each do |name|
          self.send(:define_method,name) do
            instance_variable_get("@#{name}")
          end
        end
      end

      def mc_ivar_accessor(*names)
        mc_ivar_writer(*names)
        mc_ivar_reader(*names)
      end

      def mi_ivar_accessor(*names)
        mi_ivar_writer(*names)
        mi_ivar_reader(*names)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
conglomerate-0.16.0 lib/conglomerate/mixin_ivar_helper.rb
conglomerate-0.15.0 lib/conglomerate/mixin_ivar_helper.rb
conglomerate-0.14.0 lib/conglomerate/mixin_ivar_helper.rb
conglomerate-0.13.0 lib/conglomerate/mixin_ivar_helper.rb
conglomerate-0.12.1 lib/conglomerate/mixin_ivar_helper.rb
conglomerate-0.12.0 lib/conglomerate/mixin_ivar_helper.rb
conglomerate-0.11.1 lib/conglomerate/mixin_ivar_helper.rb
conglomerate-0.11.0 lib/conglomerate/mixin_ivar_helper.rb