Inheritance: RubyModule, IDuplicable
Example #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;
        }
Example #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);
 }
Example #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);
 }
Example #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);
     }
 }
Example #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);
        }
Example #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);
 }
Example #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;
 }
Example #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;
        }
Example #9
0
        public static char Create(RubyClass/*!*/ self, [NotNull]string/*!*/ str) {
            if (str.Length == 0) {
                throw EmptyError("string");
            }

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

            return chars[0];
        }
Example #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;
 }
Example #12
0
        public static char Create(RubyClass/*!*/ self, [DefaultProtocol]MutableString/*!*/ str) {
            if (str.IsEmpty) {
                throw EmptyError("string");
            }

            return str.GetChar(0);
        }
Example #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;
 }
Example #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;
            }
Example #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);
        }
Example #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);
        }
Example #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;
        }
Example #19
0
 public static GeneratorState CreateGeneratorState(RubyClass/*!*/ self, [Optional]Hash configuration)
 {
     GeneratorState state = new GeneratorState();
     if (configuration != null) {
         Reinitialize(self.Context, state, configuration);
     }
     return state;
 }
Example #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;
        }
Example #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;
        }
Example #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;
 }
Example #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
            );
        }
Example #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);
        }
Example #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)
            );
        }
Example #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);
            }
        }
Example #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;
            }
        }
Example #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;
 }
Example #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)));
        }
Example #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);
        }
Example #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));
        }
Example #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);
        }
Example #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));
        }
Example #34
0
 public static Hash /*!*/ CreateHash([NotNull] BlockParam /*!*/ defaultProc, RubyClass /*!*/ self)
 {
     return(new Hash(self.Context.EqualityComparer, defaultProc.Proc, null));
 }
Example #35
0
 public static RubyIO /*!*/ CreateIO(RubyClass /*!*/ self)
 {
     // TODO: should create an IO object with uninitialize stream
     throw new NotImplementedException();
 }
Example #36
0
 public static RubyArray /*!*/ ReadLines(RubyClass /*!*/ self,
                                         [DefaultProtocol, NotNull] MutableString /*!*/ path)
 {
     return(ReadLines(self, path, self.Context.InputSeparator));
 }
Example #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));
 }
Example #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);
     }
 }
Example #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));
        }
Example #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;
 }
Example #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));
 }
Example #43
0
 public static void InitializeCopy(RubyClass /*!*/ self, [NotNull] RubyClass /*!*/ other)
 {
     self.InitializeClassCopy(other);
 }
Example #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)
 {
 }
Example #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");
 }
Example #47
0
 public static Hash /*!*/ CreateSubclass(RubyClass /*!*/ self)
 {
     return(Hash.CreateInstance(self));
 }
Example #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);
        }
Example #49
0
 public static Hash /*!*/ CreateHash(RubyClass /*!*/ self)
 {
     return(new Hash(self.Context.EqualityComparer));
 }
Example #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);
        }
Example #51
0
 public RubyObject(RubyClass /*!*/ cls)
 {
     Assert.NotNull(cls);
     Debug.Assert(!cls.IsSingletonClass);
     _immediateClass = cls;
 }
Example #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));
        }
Example #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));
 }
Example #54
0
 public RubyObject(RubyClass /*!*/ cls)
 {
     Assert.NotNull(cls);
     _class = cls;
 }
Example #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");
 }
Example #57
0
 public static float Create(RubyClass /*!*/ self, [DefaultProtocol] double value)
 {
     return((float)value);
 }
Example #58
0
 public static Enumerator /*!*/ Create(RubyClass /*!*/ self, object targetObject, [DefaultProtocol, Optional] string targetName,
                                       params object[] /*!*/ targetArguments)
 {
     return(Reinitialize(new Enumerator(), targetObject, targetName, targetArguments));
 }
Example #59
0
 public static void ForEach(BlockParam block, RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ path)
 {
     ForEach(block, self, path, self.Context.InputSeparator);
 }
Example #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));
        }