AddMethod() public method

public AddMethod ( RubyContext callerContext, string name, IronRuby.Runtime.Calls.RubyMemberInfo method ) : void
callerContext RubyContext
name string
method IronRuby.Runtime.Calls.RubyMemberInfo
return void
コード例 #1
0
ファイル: ModuleOps.cs プロジェクト: ife/IronLanguages
        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
ファイル: ModuleOps.cs プロジェクト: ife/IronLanguages
        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
ファイル: ModuleOps.cs プロジェクト: aslakhellesoy/ironruby
        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
ファイル: ModuleOps.cs プロジェクト: atczyc/ironruby
        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
ファイル: ModuleOps.cs プロジェクト: atczyc/ironruby
        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
ファイル: ModuleOps.cs プロジェクト: aceptra/ironruby
        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;
        }