Ruby:别名来自类的方法 [英] Ruby: Alias a method from a class
本文介绍了Ruby:别名来自类的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们以Nokogiri为例。
Let's use Nokogiri as an example.
如何重写
page = Nokogiri::HTML.parse(html)
as
page = myparse(html)
我看到了别名关键字但是由于涉及打开方法所属的任何模块/类,因此没有通用的别名方式。
I see the "alias" keyword but since it involves opening up whatever modules/classes a method belongs to, there is no universal way of aliasing.
推荐答案
在您的应用程序/类中创建一个方法来为您包装:
You could create a method in your application/class to wrap this for you:
def myparse(html)
Nokogiri::HTML.parse(html)
end
这篇关于Ruby:别名来自类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文