GeekFactory

int128.hatenablog.com

meta classにmix inした場合の影響範囲

想定通りでした。インスタンスのmeta classにクラスをmix inした場合は、そのインスタンスのみに影響します。

class X {
  def x() { 100 }
}

class Y {
  def y() { 200 }
}

def x1 = new X()
x1.metaClass.mixin Y
println x1.x()    // -> 100
println x1.y()    // -> 200

def x2 = new X()
println x2.x()    // -> 100
println x2.y()    // -> groovy.lang.MissingMethodException: No signature of method: X.y() is applicable

<200b>```