Inheritance: RubyModule, IDuplicable
Exemple #1
1
        protected RubyClass/*!*/ DefineGlobalClass(string/*!*/ name, Type/*!*/ type, RubyClass/*!*/ super, 
            Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, RubyModule[]/*!*/ mixins, Delegate[] factories) {

            RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, super, mixins, factories, _builtin);
            _context.ObjectClass.SetConstant(result.Name, result);
            return result;
        }
Exemple #2
0
 // copy ctor:
 private RubyStruct(RubyClass/*!*/ rubyClass, object[]/*!*/ data)
     : base(rubyClass)
 {
     Debug.Assert(rubyClass.StructInfo != null);
     Debug.Assert(!rubyClass.IsSingletonClass);
     _data = ArrayUtils.Copy(data);
 }
Exemple #3
0
 public static int InducedFrom(RubyClass/*!*/ self, double value)
 {
     if (value >= Int32.MinValue && value <= Int32.MaxValue) {
         return (Int32)value;
     }
     throw RubyExceptions.CreateRangeError("Float {0} out of range of {1}", value, self.Name);
 }
Exemple #4
0
 public static char Create(RubyClass/*!*/ self, int utf16) {
     try {
         return checked((char)utf16);
     } catch (OverflowException) {
         throw RubyExceptions.CreateRangeError("{0} is not a valid UTF-16 character code", utf16);
     }
 }
Exemple #5
0
        public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self, MutableString/*!*/ path, int mode) {
            if (path.IsEmpty) {
                throw new Errno.InvalidError();
            }

            return new RubyFile(self.Context, path.ConvertToString(), (RubyFileMode)mode);
        }
Exemple #6
0
 public static Hash CreateHash(BlockParam block, RubyClass/*!*/ self, object defaultValue)
 {
     if (block != null) {
         throw RubyExceptions.CreateArgumentError("wrong number of arguments");
     }
     return new Hash(self.Context.EqualityComparer, null, defaultValue);
 }
Exemple #7
0
 // called by Proc#new rule when creating a Ruby subclass of Proc:
 public Subclass(RubyClass/*!*/ rubyClass, Proc/*!*/ proc)
     : base(proc)
 {
     Assert.NotNull(rubyClass);
     Debug.Assert(!rubyClass.IsSingletonClass);
     ImmediateClass = rubyClass;
 }
Exemple #8
0
        public static MutableString/*!*/ Convert(RubyClass/*!*/ self, 
            [DefaultProtocol]MutableString/*!*/ toEncoding, [DefaultProtocol]MutableString/*!*/ fromEncoding, 
            [DefaultProtocol]MutableString/*!*/ str) {

            //return iconv(to, from, str).join;
            return null;
        }
Exemple #9
0
        public static char Create(RubyClass/*!*/ self, [NotNull]string/*!*/ str) {
            if (str.Length == 0) {
                throw EmptyError("string");
            }

            return str[0];
        }
Exemple #10
0
        public static char Create(RubyClass/*!*/ self, [NotNull]char[]/*!*/ chars) {
            if (chars.Length == 0) {
                throw EmptyError("System::Char[]");
            }

            return chars[0];
        }
Exemple #11
0
 // called by Class#new rule when creating a Ruby subclass of IO:
 public Subclass(RubyClass/*!*/ rubyClass)
     : base(rubyClass.Context)
 {
     Assert.NotNull(rubyClass);
     Debug.Assert(!rubyClass.IsSingletonClass);
     ImmediateClass = rubyClass;
 }
Exemple #12
0
        public static char Create(RubyClass/*!*/ self, [DefaultProtocol]MutableString/*!*/ str) {
            if (str.IsEmpty) {
                throw EmptyError("string");
            }

            return str.GetChar(0);
        }
Exemple #13
0
 public Subclass(RubyClass/*!*/ rubyClass, MutableString begin, MutableString end, bool excludeEnd)
     : base(begin, end, excludeEnd)
 {
     Assert.NotNull(rubyClass);
     Debug.Assert(!rubyClass.IsSingletonClass);
     ImmediateClass = rubyClass;
 }
Exemple #14
0
            public static RhoDatabase/*!*/ Create(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ dbName, [NotNull]MutableString/*!*/ dbPartition)
            {
                RhoDatabase rbDB = new RhoDatabase();
                rbDB.m_db = new DBAdapter();
                rbDB.m_db.rb_open(dbName.ToString(), dbPartition.ToString());

                return rbDB;
            }
Exemple #15
0
        public static Hash/*!*/ CreateSubclass(RubyClass/*!*/ self, params object[]/*!*/ items) {
            Debug.Assert(items.Length > 0);
            if (items.Length % 2 != 0) {
                throw RubyExceptions.CreateArgumentError("odd number of arguments for Hash");
            }

            return RubyUtils.SetHashElements(self.Context, Hash.CreateInstance(self), items);
        }
Exemple #16
0
        public static TCPSocket/*!*/ CreateTCPSocket(RubyClass/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ remoteHost, object remotePort) {
            int port = ConvertToPortNum(self.Context, remotePort);

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect(remoteHost.ConvertToString(), port);

            return new TCPSocket(self.Context, socket);
        }
Exemple #17
0
        protected RubyClass/*!*/ DefineGlobalClass(string/*!*/ name, Type/*!*/ type, bool isSelfContained, RubyClass/*!*/ super,
            Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, Action<RubyModule> constantsInitializer,
            RubyModule/*!*/[]/*!*/ mixins, params Delegate[] factories) {

            RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, constantsInitializer, super, mixins, factories, isSelfContained, _builtin);
            _context.ObjectClass.SetConstant(result.Name, result);
            return result;
        }
        protected RubyClass/*!*/ DefineGlobalClass(string/*!*/ name, Type/*!*/ type, int restrictions, RubyClass/*!*/ super,
            Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, Action<RubyModule> constantsInitializer,
            RubyModule/*!*/[]/*!*/ mixins, params Delegate[] factories) {

            RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, constantsInitializer, super, mixins, factories, (ModuleRestrictions)restrictions, _builtin);
            PublishModule(name, result);
            return result;
        }
 public static GeneratorState CreateGeneratorState(RubyClass/*!*/ self, [Optional]Hash configuration)
 {
     GeneratorState state = new GeneratorState();
     if (configuration != null) {
         Reinitialize(self.Context, state, configuration);
     }
     return state;
 }
Exemple #20
0
        /// <summary>
        /// Struct#new
        /// Creates Struct classes with the specified name and members
        /// </summary>
        private static object Create(BlockParam block, RubyClass/*!*/ self, string className, string/*!*/[]/*!*/ attributeNames) {
            var result = RubyStruct.DefineStruct(self, className, attributeNames);

            if (block != null) {
                return RubyUtils.EvaluateInModule(result, block, null, result);
            }

            return result;
        }
Exemple #21
0
        public static RubyIO/*!*/ CreateIO(RubyClass/*!*/ self, 
            [DefaultProtocol]int fileDescriptor, [DefaultProtocol, NotNull, Optional]MutableString modeString) {

            // TODO: a new RubyIO should be created here
            RubyIO result = self.Context.GetDescriptor(fileDescriptor);
            if (modeString != null) {
                result.ResetIOMode(modeString.ConvertToString());
            }
            return result;
        }
Exemple #22
0
 public static Hash/*!*/ CreateSubclass(ConversionStorage<IList>/*!*/ toAry, RubyClass/*!*/ self, [NotNull]IList/*!*/ list) {
     Hash result = Hash.CreateInstance(self);
     var toArySite = toAry.GetSite(TryConvertToArrayAction.Make(toAry.Context));
     foreach (object item in list) {
         IList pair = toArySite.Target(toArySite, item);
         if (pair != null && pair.Count >= 1 && pair.Count <= 2) {
             RubyUtils.SetHashElement(self.Context, result, pair[0], (pair.Count == 2) ? pair[1] : null);
         }
     }
     return result;
 }
Exemple #23
0
        public static Exception/*!*/ CreateMissingDefaultConstructorError(RubyClass/*!*/ rubyClass, string/*!*/ initializerOwnerName) {
            Debug.Assert(rubyClass.IsRubyClass);

            Type baseType = rubyClass.GetUnderlyingSystemType().BaseType;
            Debug.Assert(baseType != null);

            return CreateTypeError("can't allocate class `{1}' that derives from type `{0}' with no default constructor;" +
                " define {1}#new singleton method instead of {2}#initialize",
                rubyClass.Context.GetTypeName(baseType, true), rubyClass.Name, initializerOwnerName
            );
        }
Exemple #24
0
        public static object NewStruct(BlockParam block, RubyClass/*!*/ self, [DefaultProtocol]MutableString className,
            [DefaultProtocol, NotNullItems]params string/*!*/[]/*!*/ attributeNames) {

            if (className == null) {
                return Create(block, self, null, attributeNames);
            }

            string strName = className.ConvertToString();
            RubyUtils.CheckConstantName(strName);
            return Create(block, self, strName, attributeNames);
        }
Exemple #25
0
        public static TCPSocket/*!*/ CreateTCPSocket(ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, 
            RubyClass/*!*/ self, 
            [DefaultProtocol]MutableString remoteHost, object remotePort,
            [DefaultProtocol]MutableString localHost, object localPort) {

            return BindLocalEndPoint(
                CreateTCPSocket(stringCast, fixnumCast, self, remoteHost, remotePort, 0),
                localHost,
                ConvertToPortNum(stringCast, fixnumCast, localPort)
            );
        }
Exemple #26
0
        public static RubyFile/*!*/ CreateFile(RubyClass/*!*/ self,
            [DefaultProtocol]Union<int, MutableString> descriptorOrPath, int mode, [Optional]int permission) {

            if (descriptorOrPath.IsFixnum()) {
                // TODO: descriptor
                throw new NotImplementedException();
            } else {
                // TODO: permissions
                return CreateFile(self, descriptorOrPath.Second, mode);
            }
        }
Exemple #27
0
        public static RubyClass GetSuperclass(RubyClass/*!*/ self) {
            if (self.IsSingletonClass) {
                RubyClass result = self.ImmediateClass;
                Debug.Assert(result.IsSingletonClass);

                // do not return dummy singletons, also do not create a new singleton (MRI does):
                return result.IsDummySingletonClass ? self : result;
            } else {
                return self.SuperClass;
            }
        }
Exemple #28
0
 public static MutableString Convert(RubyClass/*!*/ self,
     [DefaultProtocol, NotNull]MutableString/*!*/ toEncoding, [DefaultProtocol, NotNull]MutableString/*!*/ fromEncoding, 
     [DefaultProtocol]MutableString str)
 {
     MutableString[] convertedStrings = Convert(self, toEncoding, fromEncoding, new MutableString[] { str, null });
     MutableString result = MutableString.CreateEmpty();
     foreach (MutableString s in convertedStrings) {
         result.Append(s);
     }
     return result;
 }
Exemple #29
0
        public static TCPSocket/*!*/ CreateTCPSocket(ConversionStorage<MutableString>/*!*/ stringCast, ConversionStorage<int>/*!*/ fixnumCast, 
            RubyClass/*!*/ self, [DefaultProtocol]MutableString remoteHost, object remotePort, [Optional]int localPort) {

            // Not sure what the semantics should be in this case but we make sure not to blow up.
            // Real-world code (Server.connect_to in memcache.rb in the memcache-client gem) does do "TCPSocket.new(host, port, 0)"
            if (localPort != 0) {
                throw new NotImplementedError();
            }

            return new TCPSocket(self.Context, CreateSocket(remoteHost, ConvertToPortNum(stringCast, fixnumCast, remotePort)));
        }
Exemple #30
0
        public static RubyIO/*!*/ CreateFile(
            ConversionStorage<int?>/*!*/ toInt,
            ConversionStorage<IDictionary<object, object>>/*!*/ toHash,
            ConversionStorage<MutableString>/*!*/ toStr,
            RubyClass/*!*/ self,
            object descriptor,
            [Optional]object optionsOrMode,
            [DefaultParameterValue(null), DefaultProtocol]IDictionary<object, object> options) {

            return Reinitialize(toInt, toHash, toStr, new RubyIO(self.Context), descriptor, optionsOrMode, options);
        }
Exemple #31
0
        public static object Open(RubyContext /*!*/ context, BlockParam /*!*/ block, RubyClass /*!*/ self, int fileDescriptor, [NotNull] MutableString /*!*/ mode)
        {
            RubyIO io = _CreateIOSharedSite11.Target(_CreateIOSharedSite11, context, self, fileDescriptor, mode);

            return(TryInvokeOpenBlock(context, block, io));
        }
Exemple #32
0
        public static Hash /*!*/ CreateSubclass(ConversionStorage <IList> /*!*/ toAry, RubyClass /*!*/ self, [NotNull] IList /*!*/ list)
        {
            Hash result    = Hash.CreateInstance(self);
            var  toArySite = toAry.GetSite(TryConvertToArrayAction.Make(toAry.Context));

            foreach (object item in list)
            {
                IList pair = toArySite.Target(toArySite, item);
                if (pair != null && pair.Count >= 1 && pair.Count <= 2)
                {
                    RubyUtils.SetHashElement(self.Context, result, pair[0], (pair.Count == 2) ? pair[1] : null);
                }
            }
            return(result);
        }
Exemple #33
0
        public static object Open(RubyContext /*!*/ context, BlockParam /*!*/ block, RubyClass /*!*/ self, MutableString /*!*/ host, int port)
        {
            RubyIO io = _CreateIOSharedSite6.Target(_CreateIOSharedSite6, context, self, host, port);

            return(TryInvokeOpenBlock(context, block, io));
        }
Exemple #34
0
 public static Hash /*!*/ CreateHash([NotNull] BlockParam /*!*/ defaultProc, RubyClass /*!*/ self)
 {
     return(new Hash(self.Context.EqualityComparer, defaultProc.Proc, null));
 }
Exemple #35
0
 public static RubyIO /*!*/ CreateIO(RubyClass /*!*/ self)
 {
     // TODO: should create an IO object with uninitialize stream
     throw new NotImplementedException();
 }
Exemple #36
0
 public static RubyArray /*!*/ ReadLines(RubyClass /*!*/ self,
                                         [DefaultProtocol, NotNull] MutableString /*!*/ path)
 {
     return(ReadLines(self, path, self.Context.InputSeparator));
 }
Exemple #37
0
 public static Range /*!*/ CreateRange(BinaryOpStorage /*!*/ comparisonStorage,
                                       RubyClass /*!*/ self, object begin, object end, [Optional] bool excludeEnd)
 {
     return(new Range(comparisonStorage, self.Context, begin, end, excludeEnd));
 }
Exemple #38
0
 public static void ForEach(BlockParam block, RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ path, MutableString separator)
 {
     using (RubyIO io = new RubyIO(self.Context, File.OpenRead(path.ConvertToString()), "r")) {
         Each(block, io, separator);
     }
 }
Exemple #39
0
        public static IDictionary <object, object> TryConvert(ConversionStorage <IDictionary <object, object> > /*!*/ toHash, RubyClass /*!*/ self, object obj)
        {
            var site = toHash.GetSite(TryConvertToHashAction.Make(toHash.Context));

            return(site.Target(site, obj));
        }
Exemple #40
0
 public static RubyIO ForFd(RubyClass /*!*/ self, int fileDescriptor, [DefaultProtocol, NotNull] MutableString /*!*/ modeString)
 {
     return(CreateIO(self, fileDescriptor, modeString));
 }
 // called by Class#new rule when creating a Ruby subclass:
 internal Subclass(RubyClass /*!*/ rubyClass, string name)
     : base(rubyClass, name)
 {
     Assert.NotNull(rubyClass);
     _class = rubyClass;
 }
Exemple #42
0
 public static Hash /*!*/ CreateSubclass(RubyClass /*!*/ self, [NotNull] IDictionary <object, object> /*!*/ hash)
 {
     // creates a new hash and copies entries of the given hash into it (no other objects associated with the has are copied):
     return(IDictionaryOps.ReplaceData(Hash.CreateInstance(self), hash));
 }
Exemple #43
0
 public static void InitializeCopy(RubyClass /*!*/ self, [NotNull] RubyClass /*!*/ other)
 {
     self.InitializeClassCopy(other);
 }
Exemple #44
0
 public static object OpenPipe(RubyContext /*!*/ context, BlockParam block, RubyClass /*!*/ self,
                               [DefaultProtocol, NotNull] MutableString /*!*/ command, [DefaultProtocol, Optional, NotNull] MutableString modeString)
 {
     return(TryInvokeOpenBlock(context, block, OpenPipe(context, self, command, modeString)));
 }
 // called by Class#new rule when creating a Ruby subclass:
 public Subclass(RubyClass /*!*/ rubyClass)
     : this(rubyClass, null)
 {
 }
Exemple #46
0
 public static void Reinitialize(BlockParam body, RubyClass /*!*/ self, [Optional] RubyClass superClass)
 {
     // Class cannot be subclassed, so this can only be called directly on an already initialized class:
     throw RubyExceptions.CreateTypeError("already initialized class");
 }
Exemple #47
0
 public static Hash /*!*/ CreateSubclass(RubyClass /*!*/ self)
 {
     return(Hash.CreateInstance(self));
 }
Exemple #48
0
        public static MutableString Mangle(RubyClass /*!*/ self, [DefaultProtocol] string /*!*/ clrName)
        {
            var ruby = RubyUtils.TryMangleName(clrName);

            return(ruby != null?MutableString.Create(ruby, self.Context.GetIdentifierEncoding()) : null);
        }
Exemple #49
0
 public static Hash /*!*/ CreateHash(RubyClass /*!*/ self)
 {
     return(new Hash(self.Context.EqualityComparer));
 }
Exemple #50
0
        protected RubyClass /*!*/ DefineGlobalClass(string /*!*/ name, Type /*!*/ type, RubyClass /*!*/ super,
                                                    Action <RubyModule> instanceTrait, Action <RubyModule> classTrait, RubyModule[] /*!*/ mixins, Delegate[] factories)
        {
            RubyClass result = _context.DefineLibraryClass(name, type, instanceTrait, classTrait, super, mixins, factories, _builtin);

            _context.ObjectClass.SetConstant(result.Name, result);
            return(result);
        }
Exemple #51
0
 public RubyObject(RubyClass /*!*/ cls)
 {
     Assert.NotNull(cls);
     Debug.Assert(!cls.IsSingletonClass);
     _immediateClass = cls;
 }
Exemple #52
0
        public static object Open(RubyContext /*!*/ context, BlockParam /*!*/ block, RubyClass /*!*/ self, int fileDescriptor, object mode)
        {
            RubyIO io = _CreateIOSharedSite11.Target(_CreateIOSharedSite11, context, self, fileDescriptor, Protocols.CastToString(context, mode));

            return(TryInvokeOpenBlock(context, block, io));
        }
Exemple #53
0
 protected RubyClass /*!*/ DefineClass(string /*!*/ name, Type /*!*/ type, RubyClass /*!*/ super,
                                       Action <RubyModule> instanceTrait, Action <RubyModule> classTrait, RubyModule[] /*!*/ mixins, Delegate[] factories)
 {
     return(_context.DefineLibraryClass(name, type, instanceTrait, classTrait, super, mixins, factories, _builtin));
 }
Exemple #54
0
 public RubyObject(RubyClass /*!*/ cls)
 {
     Assert.NotNull(cls);
     _class = cls;
 }
Exemple #55
0
 public static string /*!*/ GetClrMessage(RubyClass /*!*/ exceptionClass, object message)
 {
     return(RubyExceptionData.GetClrMessage(exceptionClass.Context, message));
 }
 public Meta(Expression /*!*/ expression, BindingRestrictions /*!*/ restrictions, RubyClass /*!*/ value)
     : base(expression, restrictions, value)
 {
     ContractUtils.RequiresNotNull(value, "value");
 }
 public static float Create(RubyClass /*!*/ self, [DefaultProtocol] double value)
 {
     return((float)value);
 }
Exemple #58
0
 public static Enumerator /*!*/ Create(RubyClass /*!*/ self, object targetObject, [DefaultProtocol, Optional] string targetName,
                                       params object[] /*!*/ targetArguments)
 {
     return(Reinitialize(new Enumerator(), targetObject, targetName, targetArguments));
 }
Exemple #59
0
 public static void ForEach(BlockParam block, RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ path)
 {
     ForEach(block, self, path, self.Context.InputSeparator);
 }
Exemple #60
0
        public static object Open(RubyContext /*!*/ context, BlockParam /*!*/ block, RubyClass /*!*/ self, int fileDescriptor)
        {
            RubyIO io = _CreateIOSharedSite1.Target(_CreateIOSharedSite1, context, self, fileDescriptor);

            return(TryInvokeOpenBlock(context, block, io));
        }