title: Extracting arguments into into class
body: <p>I am looking for the best way to extract a class from an argument list that has gotten too long in one of my services. I have tried following a few articles and posts on here but no luck. My code:</p>
  
  <p><strong>app/services/location/update_event.rb</strong></p>
  
  <pre><code>class Location::UpdateEvent
    def self.call(location:, event_id:, created_by:, city_details: nil, city_description: nil, city_weather: nil, city_location: nil )
      # Would like to to extract the above city arguments into its own class called city_info
  
      ActiveRecord::Base.transaction do
        LocationEvent.create(
          event: Event.find(event_id),
          location: location,
          # Here is where this data is then being sent to another servixe
          city_details: city_details,
          city_description: city_description,
          city_weather: city_weather,
          city_location: city_location,
          entered_at: Time.zone.now
        )
      end
    end
  end
  </code></pre>
  
  <p>Here is what I tried, and replaced the 4 arguments with <code>city_info:</code> in update_location.rb.</p>
  
  <p><strong>app/services/event/city_info.rb</strong></p>
  
  <pre><code>class CityInfo
    attr_accessor :city_details, :city_description, :city_weather, :city_location
  
    def initialize(
      city_details: nil,
      city_description: nil,
      city_weather: nil,
      city_location: nil)
  
      @city_details = city_details
      @city_description = city_description
      @city_weather = city_weather
      @city_location = city_location
    end
  end
  </code></pre>
  
  <p>And finally, here is the update method from the controller that originally accepts the params, and sends them to the service. These need to be able to be nil on occasion.</p>
  
  <pre><code>def update
    authorize(location)
    @location = Location::UpdateEvent.call(
      location: location,
      event_id: params[:event_id],
      created_by: current_user,
      city_details: params[:city_details],
      city_description: params[:city_description],
      city_weather: params[:city_weather],
      city_location: params[:city_location]
    )
  
    @location.reload
    @location  = LocationDecorator.new(@location)
  end
  </code></pre>