示例#1
0
        internal static void SetMethodAttributes(RubyScope /*!*/ scope, RubyModule /*!*/ module, object[] /*!*/ methodNames, RubyMethodAttributes attributes)
        {
            ContractUtils.RequiresNotNull(scope, "scope");
            ContractUtils.RequiresNotNull(methodNames, "methodNames");

            if (methodNames.Length == 0)
            {
                scope.GetMethodAttributesDefinitionScope().MethodAttributes = attributes;
            }
            else
            {
                foreach (string methodName in Protocols.CastToSymbols(scope.RubyContext, methodNames))
                {
                    RubyMemberInfo method = module.ResolveMethodFallbackToObject(methodName, true);
                    if (method == null)
                    {
                        throw RubyExceptions.CreateNameError(RubyExceptions.FormatMethodMissingMessage(scope.RubyContext, module, methodName));
                    }

                    if ((attributes & RubyMethodAttributes.ModuleFunction) == RubyMethodAttributes.ModuleFunction)
                    {
                        module.AddModuleFunction(methodName, method);
                    }
                    else
                    {
                        module.SetMethodVisibility(methodName, method, (RubyMethodVisibility)(attributes & RubyMethodAttributes.VisibilityMask));
                    }
                }
            }
        }
示例#2
0
        public static RubyModule /*!*/ AliasMethod(RubyModule /*!*/ self,
                                                   [DefaultProtocol] string /*!*/ newName, [DefaultProtocol] string /*!*/ oldName)
        {
            RubyMemberInfo method = self.ResolveMethodFallbackToObject(oldName, true);

            if (method == null)
            {
                throw RubyExceptions.CreateUndefinedMethodError(self, oldName);
            }

            self.AddMethodAlias(newName, method);
            return(self);
        }
示例#3
0
        public static RubyModule/*!*/ AliasMethod(RubyContext/*!*/ context, RubyModule/*!*/ self,
            [DefaultProtocol]string/*!*/ newName, [DefaultProtocol]string/*!*/ oldName) {

            RubyMemberInfo method = self.ResolveMethodFallbackToObject(oldName, true);
            if (method == null) {
                throw RubyExceptions.CreateUndefinedMethodError(self, oldName);
            }

            self.AddMethodAlias(context, newName, method);
            return self;
        }
示例#4
0
        internal static void SetMethodAttributes(RubyScope/*!*/ scope, RubyModule/*!*/ module, object[]/*!*/ methodNames, RubyMethodAttributes attributes) {
            ContractUtils.RequiresNotNull(scope, "scope");
            ContractUtils.RequiresNotNull(methodNames, "methodNames");

            if (methodNames.Length == 0) {
                scope.GetMethodAttributesDefinitionScope().MethodAttributes = attributes;
            } else {
                foreach (string methodName in Protocols.CastToSymbols(scope.RubyContext, methodNames)) {
                    RubyMemberInfo method = module.ResolveMethodFallbackToObject(methodName, true);
                    if (method == null) {
                        throw RubyExceptions.CreateNameError(RubyExceptions.FormatMethodMissingMessage(scope.RubyContext, module, methodName));
                    }

                    if ((attributes & RubyMethodAttributes.ModuleFunction) == RubyMethodAttributes.ModuleFunction) {
                        module.AddModuleFunction(scope.RubyContext, methodName, method);
                    } else {
                        module.SetMethodVisibility(scope.RubyContext, methodName, method, (RubyMethodVisibility)(attributes & RubyMethodAttributes.VisibilityMask));
                    }
                }
            }
        }