我想創建一個函數,通過傳遞給它的類來解決問題。重新打開這些類以添加功能的最習慣方法是什麼?這就是我的意思:如何在Ruby中使用其實例變量重新打開一個類?
def class_messer(target_object)
#would like to reopen class here with something like:
class target_object.class
#add methods
end
end
很明顯,該語法不起作用。我可以得到target_object的類,並評估一些字符串,但是感覺很糟糕。有沒有更習慣的方式來做到這一點?
完美,謝謝。 – HaskellMan