docs: public static MetaClass metaClass (Class self, Closure closure){
          MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
          MetaClass mc = metaClassRegistry.getMetaClass(self);
  
          if (mc instanceof ExpandoMetaClass) {
              ((ExpandoMetaClass) mc).define(closure);
              return mc;
          }
          else {
              if (mc instanceof DelegatingMetaClass && ((DelegatingMetaClass) mc).getAdaptee() instanceof ExpandoMetaClass) {
                  ((ExpandoMetaClass)((DelegatingMetaClass) mc).getAdaptee()).define(closure);
                  return mc;
              }
              else {
                  if (mc instanceof DelegatingMetaClass && ((DelegatingMetaClass) mc).getAdaptee().getClass() == MetaClassImpl.class) {
                      ExpandoMetaClass emc =  new ExpandoMetaClass(self, false, true);
                      emc.initialize();
                      emc.define(closure);
                      ((DelegatingMetaClass) mc).setAdaptee(emc);
                      return mc;
                  }
                  else {
                      if (mc.getClass() == MetaClassImpl.class) {
                          // default case
                          mc = new ExpandoMetaClass(self, false, true);
                          mc.initialize();
                          ((ExpandoMetaClass)mc).define(closure);
                          metaClassRegistry.setMetaClass(self, mc);
                          return mc;
                      }
                      else {
                          throw new GroovyRuntimeException("Can't add methods to custom meta class " + mc);
                      }
                  }
              }
          }
      }