How do I call a method that is a hash value?

前端 未结 7 720
后悔当初
后悔当初 2021-01-07 02:47

Previously, I asked about a clever way to execute a method on a given condition \"Ruby a clever way to execute a function on a condition.\"

The solutions and respons

相关标签:
7条回答
  • 2021-01-07 03:26

    Well, the first line in your class calls a method that doesn't exist yet. It won't even exist after the whole class is loaded though, since that would be a call to the class method and you've only defined instance methods.

    Also keep in mind that {0 => a()} will call the method a(), not create a reference to the method a(). If you wanted to put a function in there that doesn't get evaluated until later, you'd have to use some kind of Lambda.

    0 讨论(0)
提交回复
热议问题