4 ms·
What if you could require() your patch just where you needed it? You'd have the utility and elegance of the simple solution, without abusing the global namespac
by ssmoot 11y ago
What if you could require() your patch just where you needed it? You'd have the utility and elegance of the simple solution, without abusing the global namespace.
That's exactly what you'd do in Scala.
implicit class HtmlHelpers(node: Node) {
def id: String = node \ "@id" text
def name: String = node \ "@name" text
def cssClass: String = node \ "@class" text
def href: String = node \ "@href" text
}
And I haven't abused anything. Whenever I need it, even within another method, I can just import until.HtmlHelpers.
- joshguthrie 11y agorefines are coming soon into ruby-core (2.2.0 IIRC).