0

I am fairly new to Ruby. I have few lines of code I want to DRY them.

foo_attributes = params[:foo]
params.delete(:foo)
bar_attributes = params[:bar]
params.delete(:bar)

I am trying to do something like this

["foo", "bar"].each do |par|
  par_attribute = params[:par]
  params.delete(:par)
end

Later in my method, I need to call other methods passing the objects foo_attribute, bar_attribute.

Like:

call_foo_method(foo_attribute)

How can I do this in ruby?

1

1 Answer 1

0

Why don't you just keep the params var? Then you don't have to assign any other variable at all?

You can also DRY the first (and second example) by combinig two lines:

foo_attributes = params.delete(:foo)
bar_attributes = params.delete(:bar)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.