lib/type_contracts/overrides.rb
def attr_accessor(first_property, *other)
      annotation = @__type_contracts__last_annotation
      @__type_contracts__last_annotation = nil
      return super unless self.is_a?(Module) && TypeContracts.config.enabled?

      # No annotations, don't bother redefining stuff.
      return super unless annotation

      property_names = ([first_property] + other).map(&:to_sym)
      property_names.each do |property|
        class_eval <<~RUBY
          def #{property}; @#{property}; end                 # def some_property; @some_property; end
          def #{property}=(value); @#{property} = value; end # def some_property=(value); @some_property = value; end
        RUBY

        if annotation
          getter_copy = __clone_annotation_for_method(annotation, :"#{property}")
          getter_copy[:params] = nil

          setter_copy = __clone_annotation_for_method(annotation, :"#{property}=")
          setter_copy[:return] = nil

          getter_copy[:_redefiner].redefine!(getter_copy)
          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.  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_accessor(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}; @#{property}; end                 # def some_property; @some_property; end
          def #{property}=(value); @#{property} = value; end # def some_property=(value); @some_property = value; end
        RUBY
        if annotation
          getter_copy = __clone_annotation_for_method(annotation, :"#{property}")
          getter_copy[:params] = nil
          setter_copy = __clone_annotation_for_method(annotation, :"#{property}=")
          setter_copy[:return] = nil
          getter_copy[:_redefiner].redefine!(getter_copy)
          setter_copy[:_redefiner].redefine!(setter_copy)
        end
      end
    end
def attr_accessor ( 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 } ; @ #{ property } ; end                 # def some_property; @some_property; end
          def  #{ property } =(value); @ #{ property }  = value; end # def some_property=(value); @some_property = value; end
         RUBY if annotation getter_copy = __clone_annotation_for_method ( annotation , :" #{ property } " ) getter_copy [ :params ] = nil setter_copy = __clone_annotation_for_method ( annotation , :" #{ property } = " ) setter_copy [ :return ] = nil getter_copy [ :_redefiner ] . redefine! ( getter_copy ) 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 .
# No annotations, don't bother redefining stuff.
first_property
other