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

前端 未结 7 766
后悔当初
后悔当初 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:10

    that code doesn't work. it executes a at the time it is added to the hash, not when it is retrieved from the hash (try it in irb).

    It doesn't work in the class because there is no a method defined on the class (you eventually define a method a on the instance.

    Try actually using lambdas like

    {0 => lambda { puts "hello world" }} 
    

    instead

提交回复
热议问题