themirror
themirror

Reputation: 10287

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 universal way of aliasing.

Upvotes: 2

Views: 735

Answers (1)

Dylan Markow
Dylan Markow

Reputation: 124419

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

def myparse(html)
  Nokogiri::HTML.parse(html)
end

Upvotes: 5

Related Questions