alias :new_method, :new_method
----------------------------------------------------
alias的用法
class MyClass
def my_method
puts 'hello'
end
alias :new_method :my_method
end
my_class = MyClass.new
my_class.new_method
# hello
----------------------------------------------------
alias_method 的用法
module Mod
alias_method :origExit, :exit
def exit(code=0)
print "Exiting with code #{code}\n"
origExit(code)
end
end
include Mod
exit(99)
# Exiting with code 99
沒有留言:
張貼留言