Reputation: 413
I have this:
def some_method()
if auto_pagination
customers_list.auto_paging_each do |customer|
customer_hash = importer.extract(customer)
arr << customer_hash
end
else
customers_list.each do |customer|
customer_hash = importer.extract(customer)
arr << customer_hash
end
end
end
I would like to refactor it in a shorter version. I though about send method but with the block I turns out a bit tricky. Any ideas?
Upvotes: 0
Views: 34
Reputation: 28285
I though about send method but with the block I turns out a bit tricky
I'm not sure what you mean by "tricky", but:
def some_method()
method_name = auto_pagination ? :auto_paging_each : :each
customers_list.send(method_name) do |customer|
customer_hash = importer.extract(customer)
arr << customer_hash
end
end
Upvotes: 3