开发者

Ruby: Alias a method from a class

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 uni开发者_开发技巧versal 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜