module Meta
alias_method :facebook,:exit #=> :orig_exit
def meth1
[1, 2, 3, 4, 5]
end
def meth2
[11, 21, 31, 41, 51]
end
def meth3
[4, 5, 6, 7, 8]
end
def exit(code=0)
puts "Exiting with code #{code}"
puts([9, 10, 11, 12, 13])
facebook(100)
end
end
include Meta
exit(100)
Exiting with code 100
9
10
11
12
13
class A
def method_1
p "This is method 1 in A"
end
def A.重命名
alias_method :method_2,:method_1
end
end
class B < A
def method_1
p "This is method 1 in B"
end
重命名
end
B.new.method_2
"This is method 1 in B"
开发工具:RubyMine 2022.2.1
参考文献:https://www.jianshu.com/p/946202f008a8