Search code examples
rubyhashmetaprogrammingruby-hash

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


Solution

  • You can try something like:

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