如何在不使用 eval 的情况下更改以下代码。有没有一种方法可以在初始化堆时根据参数对 getroot 函数起别名。
class Heap
  def initialize arr,type=:min
     newfunc = "get#{type.to_s}".to_sym
     eval ("class << self; alias #{newfunc} :getroot; end")
  end
  def getroot     
     puts "Inside Getroot"
  end
end
a = Heap.new([1,2,3],:max)
a.getmax                      #prints Inside Getroot
b = Heap.new([1,2,3],:min)
b.getmin                      #prints Inside Getroot