我想重構這個代碼:如何在Ruby中使用帶有參數的別名?
class Logger
class << self
def info title, msg
puts hash_for(title, msg, :info).to_json
end
def unknown title, msg
puts hash_for(title, msg, :unknown).to_json
end
成類似:
def print title, msg, level
puts hash_for(title, msg, level).to_json
end
alias :info, :print
alias :unknown, :print
但我需要注入的說法,這alias
和alias_method
似乎並不支持。
紅寶石2.3
是的,這似乎是一個好方法... –