Dynamic Hash in Ruby
Youssef Chaker
31

Sounds like a great case for extracting out a new object, say TestObjectDefinition , that addresses this, and a TestUser class that inherits from or imports from it and defers to the relevant model class:

class TestUser < TestObjectDefinition.new(User)
def initialize(default_params = {})
self.default_params = default_params
end
  def seed(specific_params)
load_or_create default_params.merge(specific_params)
# ...
end
end

Which would tidy up those seeds significantly:

user = TestUser.initialize(default: true)
user.seed(default: false, foo: 'Foo!')
Like what you read? Give Corey Ward a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.