class Time def parse(str) @time = # I want to use Time.parse here end end
require 'time' class Time #Opening the singleton class as Time.parse is a singleton method class << self alias_method :orig_parse, :parse def parse(str) @time = orig_parse str end end end
现在您仍然可以使用 Time.orig_parse
Time.orig_parse