How can i change the following code without using eval. Is there a way i can alias the getroot function based on argument when initializing the Heap.
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
Is this satisfactory?