AddMethod() публичный Метод

public AddMethod ( RubyContext callerContext, string name, IronRuby.Runtime.Calls.RubyMemberInfo method ) : void
callerContext RubyContext
name string
method IronRuby.Runtime.Calls.RubyMemberInfo
Результат void
Пример #1
0
        public static Proc /*!*/ DefineMethod(RubyScope /*!*/ scope, RubyModule /*!*/ self,
                                              [DefaultProtocol, NotNull] string /*!*/ methodName, [NotNull] Proc /*!*/ block)
        {
            var visibility = GetDefinedMethodVisibility(scope, self, methodName);
            var info       = Proc.ToLambdaMethodInfo(block, methodName, visibility, self);

            self.AddMethod(scope.RubyContext, methodName, info);
            return(info.Lambda);
        }
Пример #2
0
        public static Proc /*!*/ DefineMethod(RubyScope /*!*/ scope, RubyModule /*!*/ self,
                                              [DefaultProtocol] string /*!*/ methodName, [NotNull] Proc /*!*/ method)
        {
            // MRI: ignores ModuleFunction scope flag (doesn't create singleton method).
            // MRI 1.8: uses private visibility if module_function is applied (bug).
            // MFI 1.9: uses public visibility as we do, unless the name is special.
            var visibility = RubyUtils.GetSpecialMethodVisibility(scope.Visibility, methodName);

            self.AddMethod(methodName, Proc.ToLambdaMethodInfo(method.ToLambda(), methodName, visibility, self));
            return(method);
        }
Пример #3
0
        private static void DefineAccessor(RubyScope /*!*/ scope, RubyModule /*!*/ self, string /*!*/ name, bool readable, bool writable)
        {
            // MRI: ignores ModuleFunction scope flag (doesn't create singleton methods):

            if (!Tokenizer.IsVariableName(name))
            {
                throw RubyExceptions.CreateNameError("invalid attribute name `{0}'", name);
            }

            var varName         = "@" + name;
            var attributesScope = scope.GetMethodAttributesDefinitionScope();

            if (readable)
            {
                var flags = (RubyMemberFlags)RubyUtils.GetSpecialMethodVisibility(attributesScope.Visibility, name);
                self.AddMethod(scope.RubyContext, name, new RubyAttributeReaderInfo(flags, self, varName));
            }

            if (writable)
            {
                self.AddMethod(scope.RubyContext, name + "=", new RubyAttributeWriterInfo((RubyMemberFlags)attributesScope.Visibility, self, varName));
            }
        }
Пример #4
0
        // thread-safe:
        private static void SetLibraryMethod(RubyModule /*!*/ module, string /*!*/ name, RubyMemberInfo /*!*/ method, bool noEvent)
        {
            var context = module.Context;

            // trigger event only for non-builtins:
            if (noEvent)
            {
                // TODO: hoist lock?
                using (context.ClassHierarchyLocker()) {
                    module.SetMethodNoMutateNoEventNoLock(context, name, method);
                }
            }
            else
            {
                module.AddMethod(context, name, method);
            }
        }
Пример #5
0
        public static Proc/*!*/ DefineMethod(RubyScope/*!*/ scope, RubyModule/*!*/ self, 
            [DefaultProtocol]string/*!*/ methodName, [NotNull]Proc/*!*/ method) {

            // MRI: ignores ModuleFunction scope flag (doesn't create singleton method).
            // MRI 1.8: uses private visibility if module_function is applied (bug).
            // MFI 1.9: uses public visibility as we do, unless the name is special.
            var visibility = RubyUtils.GetSpecialMethodVisibility(scope.Visibility, methodName);

            self.AddMethod(scope.RubyContext, methodName, Proc.ToLambdaMethodInfo(method.ToLambda(), methodName, visibility, self));
            return method;
        }
Пример #6
0
 // thread-safe:
 private static void SetLibraryMethod(RubyModule/*!*/ module, string/*!*/ name, RubyMemberInfo/*!*/ method, bool noEvent) {
     var context = module.Context;
     // trigger event only for non-builtins:
     if (noEvent) {
         // TODO: hoist lock?
         using (context.ClassHierarchyLocker()) {
             module.SetMethodNoMutateNoEventNoLock(context, name, method);
         }
     } else {
         module.AddMethod(context, name, method);
     }
 }
Пример #7
0
        private static void DefineAccessor(RubyScope/*!*/ scope, RubyModule/*!*/ self, string/*!*/ name, bool readable, bool writable) {
            // MRI: ignores ModuleFunction scope flag (doesn't create singleton methods):

            if (!Tokenizer.IsVariableName(name, true)) {
                throw RubyExceptions.CreateNameError("invalid attribute name `{0}'", name);
            }

            var varName = "@" + name;
            var attributesScope = scope.GetMethodAttributesDefinitionScope();

            if (readable) {
                var flags = (RubyMemberFlags)RubyUtils.GetSpecialMethodVisibility(attributesScope.Visibility, name);
                self.AddMethod(scope.RubyContext, name, new RubyAttributeReaderInfo(flags, self, varName));
            }
            
            if (writable) {
                self.AddMethod(scope.RubyContext, name + "=", new RubyAttributeWriterInfo((RubyMemberFlags)attributesScope.Visibility, self, varName));
            }
        }
Пример #8
0
        public static Proc/*!*/ DefineMethod(RubyScope/*!*/ scope, RubyModule/*!*/ self, 
            [DefaultProtocol, NotNull]string/*!*/ methodName, [NotNull]Proc/*!*/ block) {

            var visibility = GetDefinedMethodVisibility(scope, self, methodName);
            var info = Proc.ToLambdaMethodInfo(block, methodName, visibility, self);
            self.AddMethod(scope.RubyContext, methodName, info);
            return info.Lambda;
        }
Пример #9
0
        public static Proc/*!*/ DefineMethod(RubyScope/*!*/ scope, RubyModule/*!*/ self, 
            [DefaultProtocol, NotNull]string/*!*/ methodName, [NotNull]Proc/*!*/ method) {

            var visibility = GetDefinedMethodVisibility(scope, self, methodName);
            self.AddMethod(scope.RubyContext, methodName, Proc.ToLambdaMethodInfo(method.ToLambda(), methodName, visibility, self));
            return method;
        }