aboutsummaryrefslogblamecommitdiffstats
path: root/actionmailer/lib/action_mailer/adv_attr_accessor.rb
blob: b1f5d4540bb1728d2711c2c82f9c509704c51713 (plain) (tree)
1
2
3
4
5
6
7
8
                   
                                 




                                  
                                















                                                                                           


       
 
                   
                                 




                                  
                                



















                                                                                           
module ActionMailer
  module AdvAttrAccessor #:nodoc:
    def self.append_features(base)
      super
      base.extend(ClassMethods)
    end

    module ClassMethods #:nodoc:
      def adv_attr_accessor(*names)
        names.each do |name|
          define_method("#{name}=") do |value|
            instance_variable_set("@#{name}", value)
          end

          define_method(name) do |*parameters|
            raise ArgumentError, "expected 0 or 1 parameters" unless parameters.length <= 1
            if parameters.empty?
              instance_variable_get("@#{name}")
            else
              instance_variable_set("@#{name}", parameters.first)
            end
          end
        end
      end
    end
  end
end

module ActionMailer
  module AdvAttrAccessor #:nodoc:
    def self.append_features(base)
      super
      base.extend(ClassMethods)
    end

    module ClassMethods #:nodoc:
      def adv_attr_accessor(*names)
        names.each do |name|
          define_method("#{name}=") do |value|
            instance_variable_set("@#{name}", value)
          end

          define_method(name) do |*parameters|
            raise ArgumentError, "expected 0 or 1 parameters" unless parameters.length <= 1
            if parameters.empty?
              instance_variable_get("@#{name}")
            else
              instance_variable_set("@#{name}", parameters.first)
            end
          end
        end
      end

    end
  end
end