0

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

Daniel
  • 153
  • 2
  • 12
  • If you can change `print_hash`, change it to `print_hash(*hashes)`. Then you can simply say `print_hash @hash1, @hash2, @hash3`. `hashes` is an array you then iterate inside the method. – Phlip May 11 '18 at 17:44

1 Answers1

1

You can try something like:

[@hash1, @hash2, @hash3].each(&method(:print_hash))
potashin
  • 44,205
  • 11
  • 83
  • 107