lib/type_contracts/overrides.rb
# Need to redefine attr_accessor to not use dynamic method generation with define_method,
# but use explicit ruby syntax.  Otherwise, method_added can't know about the params list.
# Also, the method_added callback would only trigger annotations for the first method
# generated (the getter), so annotations wouldn't apply to the rest.  We're cloning the
# annotation for each set of methods generated for each property here.
Need to redefine attr_accessor to not use dynamic method generation with define_method,
but use explicit ruby syntax.  Otherwise, method_added can't know about the params list.
Also, the method_added callback would only trigger annotations for the first method
generated (the getter), so annotations wouldn't apply to the rest.  We're cloning the
annotation for each set of methods generated for each property here.
Need to redefine attr_accessor to not use dynamic method generation with define_method but use explicit ruby syntax . Otherwise method_added can ' t know about the params list . Also the method_added callback would only trigger annotations for the first method generated ( the getter ) so annotations wouldn ' t apply to the rest . We ' re cloning the annotation for each set of methods generated for each property here .
def attr_writer(first_property, *other)
      annotation = @__type_contracts__last_annotation
      @__type_contracts__last_annotation = nil
      return super unless self.is_a?(Module) && TypeContracts.config.enabled?
      return super unless annotation
      property_names = ([first_property] + other).map(&:to_sym)
      property_names.each do |property|
        class_eval <<~RUBY
          def #{property}=(value); @#{property} = value; end # def some_property=(value); @some_property = value; end
        RUBY
        if annotation
          setter_copy = __clone_annotation_for_method(annotation, :"#{property}=")
          setter_copy[:return] = nil
          setter_copy[:_redefiner].redefine!(setter_copy)
        end
      end
    end
def attr_writer ( first_property , * other ) annotation = @__type_contracts__last_annotation @__type_contracts__last_annotation = nil return super unless self . is_a? ( Module ) && TypeContracts . config . enabled? return super unless annotation property_names = ( [ first_property ] + other ) . map ( & :to_sym ) property_names . each do | property | class_eval <<~RUBY 
          def  #{ property } =(value); @ #{ property }  = value; end # def some_property=(value); @some_property = value; end
         RUBY if annotation setter_copy = __clone_annotation_for_method ( annotation , :" #{ property } = " ) setter_copy [ :return ] = nil setter_copy [ :_redefiner ] . redefine! ( setter_copy ) end end end
Need to redefine attr_accessor to not use dynamic method generation with define_method,
but use explicit ruby syntax.
Need to redefine attr_accessor to not use dynamic method generation with define_method but use explicit ruby syntax .
# annotations fail when the built-in attr_writer method is called, due it generating methods # without parameter names, so just delete the last annotation # No annotations, don't bother redefining stuff.
first_property
other