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

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

    table = {
      :a => 'test',
      :b => 12,
      :c => lambda { "Hallo" },
      :d => def print(); "Hallo in test"; end
    }
    
    puts table[:a]
    puts table[:b]
    puts table[:c].call
    puts table[:d].send( :print )
    

提交回复
热议问题