Exemple #1
0
 public static MutableString ToString(RubyContext /*!*/ context, IDictionary <object, object> /*!*/ self)
 {
     using (IDisposable handle = RubyUtils.InfiniteToSTracker.TrackObject(self)) {
         if (handle == null)
         {
             return(MutableString.Create("{...}"));
         }
         else
         {
             return(IListOps.Join(context, ToArray(self)));
         }
     }
 }
Exemple #2
0
 public static MutableString /*!*/ ToMutableString(ConversionStorage <MutableString> /*!*/ tosConversion,
                                                   IDictionary <object, object> /*!*/ self)
 {
     using (IDisposable handle = RubyUtils.InfiniteToSTracker.TrackObject(self)) {
         if (handle == null)
         {
             return(MutableString.CreateAscii("{...}"));
         }
         else
         {
             return(IListOps.Join(tosConversion, ToArray(self)));
         }
     }
 }
Exemple #3
0
        public static Thread /*!*/ CreateThread(RubyContext /*!*/ context, BlockParam startRoutine, object self, [NotNull] params object[] /*!*/ args)
        {
            if (startRoutine == null)
            {
                throw new ThreadError("must be called with a block");
            }
            ThreadGroup group  = Group(Thread.CurrentThread);
            Thread      result = new Thread(new ThreadStart(delegate() {
                RubyThreadInfo info = RubyThreadInfo.FromThread(Thread.CurrentThread);
                info.Group          = group;

                try {
                    object threadResult;
                    // TODO: break?
                    startRoutine.Yield(args, out threadResult);
                    info.Result = threadResult;
#if !SILVERLIGHT
                } catch (ThreadInterruptedException) {
                    // Do nothing with this for now
#endif
                } catch (Exception e) {
                    info.Exception = e;

                    Utils.Log(
                        e.Message + "\r\n\r\n" +
                        e.StackTrace + "\r\n\r\n" +
                        IListOps.Join(context, RubyExceptionData.GetInstance(e).Backtrace).ToString(),
                        "THREAD"
                        );

                    if (_globalAbortOnException || info.AbortOnException)
                    {
                        throw;
                    }
                }
            }));

            result.Start();
            return(result);
        }
Exemple #4
0
        public static MutableString /*!*/ ToPrintedString(RubyContext /*!*/ context, object obj)
        {
            IDictionary <object, object> hash;
            List <object> list;
            MutableString str;

            if ((list = obj as List <object>) != null)
            {
                return(IListOps.Join(context, list, Environment.NewLine));
            }
            else if ((hash = obj as IDictionary <object, object>) != null)
            {
                return(IDictionaryOps.ToString(context, hash));
            }
            else if (obj == null)
            {
                return(MutableString.Create("nil"));
            }
            else if (obj is bool)
            {
                return(MutableString.Create((bool)obj ? "true" : "false"));
            }
            else if (obj is double)
            {
                var result = MutableString.Create(obj.ToString());
                if ((double)(int)(double)obj == (double)obj)
                {
                    result.Append(".0");
                }
                return(result);
            }
            else if ((str = obj as MutableString) != null)
            {
                return(str);
            }
            else
            {
                return(RubySites.ToS(context, obj));
            }
        }