示例#1
0
        public static UnboundMethod /*!*/ DefineMethod(RubyModule /*!*/ self,
                                                       [DefaultProtocol] string /*!*/ methodName, [NotNull] UnboundMethod /*!*/ method)
        {
            // MRI 1.8 does the check when the method is called, 1.9 checks it upfront as we do:
            if (!self.HasAncestor(method.TargetConstraint))
            {
                throw RubyExceptions.CreateTypeError(
                          String.Format("bind argument must be a subclass of {0}", method.TargetConstraint.Name)
                          );
            }

            self.AddDefinedMethod(methodName, method.Info);
            return(method);
        }
示例#2
0
        public static UnboundMethod/*!*/ DefineMethod(RubyContext/*!*/ context, RubyModule/*!*/ self, 
            [DefaultProtocol]string/*!*/ methodName, [NotNull]UnboundMethod/*!*/ method) {

            // MRI 1.8 does the check when the method is called, 1.9 checks it upfront as we do:
            if (!self.HasAncestor(method.TargetConstraint)) {
                throw RubyExceptions.CreateTypeError(
                    String.Format("bind argument must be a subclass of {0}", method.TargetConstraint.GetName(context))
                );
            }

            self.AddDefinedMethod(context, methodName, method.Info);
            return method;
        }
示例#3
0
        public static RubyMethod/*!*/ DefineMethod(RubyModule/*!*/ self, 
            [DefaultProtocol]string/*!*/ methodName, [NotNull]RubyMethod/*!*/ method) {

            // MRI 1.8 does the check when the method is called, 1.9 checks it upfront as we do:
            var targetClass = method.GetTargetClass();
            if (!self.HasAncestor(targetClass)) {
                throw RubyExceptions.CreateTypeError(
                    String.Format("bind argument must be a subclass of {0}", targetClass.Name)
                );
            }

            self.AddDefinedMethod(methodName, method.Info);
            return method;
        }