Ruby: methods as array elements - how do they work?

前端 未结 6 1843
一向
一向 2021-02-19 05:58

This probably isn\'t something you should try at home, but for some reason or another I tried to create an array of methods in Ruby.

I started by defining two methods.

6条回答
  •  忘了有多久
    2021-02-19 07:02

    Your code runs the two methods because you're actually calling the methods when you say "test1" and "test2" - parentheses are optional for ruby method calls.

    Since both of your methods just contain a "puts", which returns nil, your resulting array is just an array of two nils.

提交回复
热议问题