# Rails initializer to be more clean [closed]

I need a little bit of refactor my initialize method because I think it will make initializer more flexible and readable.

class LogAdminData
DEFAULT_EXCLUDED_PARAMS = %w[
].freeze

def initialize(admin_obj:, action_type:, old_data:, new_data:, excluded_params: %w[])
excluded_params += DEFAULT_EXCLUDED_PARAMS
@old_data = old_data.reject { |k, _v| excluded_params.include? k }
@new_data = new_data.reject { |k, _v| excluded_params.include? k }
@action_type = action_type
end

def call
action_type: action_type,
new_data: new_data,
old_data: old_data,
)
end


Maybe something like

  def cleanup_data(data)
excluded_params += DEFAULT_EXCLUDED_PARAMS
data.reject { |k, _v| excluded_params.include? k }
end


But how to call it in initializer using old_data and new_data?

## closed as unclear what you're asking by 200_success, dfhwze, Heslacher, AlexV, DannnnoSep 12 at 14:05

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• What does this code do, and how is it used? Is this the entire class? As it is, it looks like some essential parts of the code are missing, and your question makes little sense. – 200_success Sep 12 at 3:24

@old_data = old_data.reject { |k, _v| excluded_params.include? k } with @old_data = old_data.except(excluded_params)