Skip to content

Instantly share code, notes, and snippets.

@notyy
Created July 27, 2013 03:29
Show Gist options
  • Save notyy/6093587 to your computer and use it in GitHub Desktop.
Save notyy/6093587 to your computer and use it in GitHub Desktop.
this implicit works for scala
package com.github.notyy.retroboard.util
import org.scalatest.FunSpec
import org.scalatest.matchers.ShouldMatchers
trait Base {
protected def getChildren: List[String]
}
object Base {
implicit class SBase[T <: Base](child: T) {
def apply = child.getChildren
}
}
class Child1 extends Base {
protected def getChildren: List[String] = List("child1")
}
class Child2 extends Base {
def getChildren: List[String] = List("child2")
}
class InheritenceSpec extends FunSpec with ShouldMatchers {
describe("SBase") {
it("should add apply method to all children of Base") {
println(new Child1().apply)
println(new Child2().apply)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment