Ruby: Alias a method from a class

2019-07-14 02:45发布

Let's use Nokogiri as an example.

How can I rewrite

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.

标签: ruby alias
1条回答
放我归山
2楼-- · 2019-07-14 03:07

You could create a method in your application/class to wrap this for you:

def myparse(html)
  Nokogiri::HTML.parse(html)
end
查看更多
登录 后发表回答