title: How can I add a method to a FactoryBot factory?
body: <p>Say I have a class called storage values that holds an array of values:</p>
  
  <pre><code>class Storage
    attr_accessor :values 
  
    def initialize(*vals)
      @values = vals
    end 
  end
  </code></pre>
  
  <p>And a Factory set up for this class </p>
  
  <pre><code>FactoryBot.define do
    factory :storage do
      values { [1, 2, 3] }
    end
  end
  </code></pre>
  
  <p>How can I add a convenience method for editing the values? </p>
  
  <p>I want to have the ability to call a method called #use_values on a preexisting factory to update it, like so:</p>
  
  <pre><code>factory = FactoryBot.build(:storage)
  factory.values #=&gt; [1, 2, 3]
  
  factory.use_values(4, 5, 6)
  factory.values #=&gt; [4, 5, 6]
  </code></pre>
  
  <p>I would expect the syntax to look something like this (all though this doesn't work):</p>
  
  <pre><code>FactoryBot.define do
    factory :storage do
      values { [1, 2, 3] }
  
      def use_values(*vals)
        self.values = vals
      end
    end
  end
  </code></pre>
  
  <p>How can I do this?</p>
  
  <p>I assume this should be pretty easy to do, but I can't seem to find any good resources on it. </p>
  
  <p><strong>Note</strong> </p>
  
  <p>I'm aware that I can use options in the initial build to specify the #values return value like so:</p>
  
  <pre><code>FactoryBot.build(:storage, values: [4, 5, 6])
  </code></pre>
  
  <p>This is not what I want. I want a way to call a method on an already existing factory to update it, not build a factory with specific values.</p>