Daniel
Daniel

Reputation: 153

Call the same method but with different arguments, better way

I have something like this in my function with calls the print_hash function three times but with different args. How to do it nicer? The print_hash function is just only about print key and value.

print_hash(@hash1)
print_hash(@hash2)
print_hash(@hash3)

Thanks in advance

Upvotes: 0

Views: 100

Answers (1)

potashin
potashin

Reputation: 44601

You can try something like:

[@hash1, @hash2, @hash3].each(&method(:print_hash))

Upvotes: 1

Related Questions