public static RubyArray /*!*/ Sort(RubyContext /*!*/ context, BlockParam block, RubyArray /*!*/ self) { RubyArray result = self.CreateInstance(); IListOps.Replace(context, result, self); return(SortInPlace(context, block, result)); }
public static object Sort(ComparisonStorage /*!*/ comparisonStorage, BlockParam block, RubyArray /*!*/ self) { RubyArray result = self.CreateInstance(); IListOps.Replace(result, self); return(SortInPlace(comparisonStorage, block, result)); }
public static RubyArray GetGroup(RubyContext /*!*/ context, MatchData /*!*/ self, [NotNull] Range /*!*/ range) { int begin, count; if (!IListOps.NormalizeRange(context, self.Groups.Count, range, out begin, out count)) { return(null); } return(GetGroup(context, self, begin, count)); }
public static RubyArray GetGroup(ConversionStorage <int> /*!*/ fixnumCast, MatchData /*!*/ self, [NotNull] Range /*!*/ range) { int begin, count; if (!IListOps.NormalizeRange(fixnumCast, self.GroupCount, range, out begin, out count)) { return(null); } return(GetGroup(self, begin, count)); }
private static RubyArray /*!*/ Reinitialize(RubyArray /*!*/ self, IList /*!*/ other) { Assert.NotNull(self, other); if (other != self) { self.Clear(); IListOps.AddRange(self, other); } return(self); }
public static bool Equals(BinaryOpStorage /*!*/ equals, RubyStruct /*!*/ self, object obj) { var other = obj as RubyStruct; if (!self.StructReferenceEquals(other)) { return(false); } Debug.Assert(self.ItemCount == other.ItemCount); return(IListOps.Equals(equals, self.Values, other.Values)); }
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))); } } }
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))); } } }
public static RubyArray GetGroup(MatchData /*!*/ self, [DefaultProtocol] int start, [DefaultProtocol] int length) { if (!IListOps.NormalizeRange(self.GroupCount, ref start, ref length)) { return(null); } RubyArray result = new RubyArray(); for (int i = 0; i < length; i++) { result.Add(self.GetGroupValue(start + i)); } return(result); }
public static void Puts(BinaryOpStorage /*!*/ writeStorage, ConversionStorage <MutableString> /*!*/ tosConversion, ConversionStorage <IList> /*!*/ tryToAry, object self, [NotNull] object /*!*/ val) { IList list = Protocols.TryCastToArray(tryToAry, val); if (list != null) { IEnumerable recEnum = IListOps.EnumerateRecursively(tryToAry, list, (_) => MutableString.CreateAscii("[...]")); foreach (object item in recEnum ?? list) { Puts(writeStorage, self, ToPrintedString(tosConversion, item)); } } else { Puts(writeStorage, self, ToPrintedString(tosConversion, val)); } }
public void IListOps_EnumerateRecursively1() { var a = new RubyArray(); var b = new RubyArray(); b.Add(new RubyArray { new RubyArray { b } }); a.Add(b); var result = IListOps.EnumerateRecursively(new Runtime.ConversionStorage <System.Collections.IList>(Context), a, -1, list => { Assert(list == b); return(123); }).ToArray(); Assert(result.Length == 1 && (int)result[0] == 123); }
public static object ReverseEach(RubyContext /*!*/ context, BlockParam block, RubyArray /*!*/ self) { Assert.NotNull(context, self); if (self.Count > 0 && block == null) { throw RubyExceptions.NoBlockGiven(); } foreach (int index in IListOps.ReverseEnumerateIndexes(self)) { object result; if (block.Yield(self[index], out result)) { return(result); } } return(self); }
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)); } }
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); }
public static IList /*!*/ Flatten(ConversionStorage <IList> /*!*/ tryToAry, IDictionary <object, object> /*!*/ self, [DefaultProtocol, DefaultParameterValue(1)] int maxDepth) { if (maxDepth == 0) { return(ToArray(self)); } if (maxDepth > 0) { maxDepth--; } RubyArray result = new RubyArray(); IList list; foreach (KeyValuePair <object, object> pair in self) { if (maxDepth != 0 && (list = Protocols.TryCastToArray(tryToAry, pair.Key)) != null) { IListOps.Flatten(tryToAry, list, maxDepth - 1, result); } else { result.Add(pair.Key); } if (maxDepth != 0 && (list = Protocols.TryCastToArray(tryToAry, pair.Value)) != null) { IListOps.Flatten(tryToAry, list, maxDepth - 1, result); } else { result.Add(pair.Value); } } return(result); }
public static MutableString GetGroup(MatchData /*!*/ self, [DefaultProtocol] int index) { index = IListOps.NormalizeIndex(self.GroupCount, index); return(self.GetGroupValue(index)); }
public static object EditDocument(YamlStream /*!*/ self, [DefaultProtocol] int index, object document) { return(IListOps.SetElement(self._documents, index, document)); }
public static object GetDocument(RubyContext /*!*/ context, YamlStream /*!*/ self, [DefaultProtocol] int index) { return(IListOps.GetElement(self._documents, index)); }
public static RubyArray Add(YamlStream /*!*/ self, object document) { IListOps.Append(self._documents, document); return(self._documents); }
public static object EditDocument(RubyContext /*!*/ context, YamlStream /*!*/ self, object index, object document) { return(IListOps.SetElement(context, self.Documents, Protocols.CastToFixnum(context, index), document)); }
public static object GetDocument(RubyContext /*!*/ context, YamlStream /*!*/ self, object index) { return(IListOps.GetElement(self.Documents, Protocols.CastToFixnum(context, index))); }
public static RubyArray Add(RubyContext /*!*/ context, YamlStream /*!*/ self, object document) { return(IListOps.Append(context, self.Documents, document) as RubyArray); }