public static void RequiresNotFrozen(RubyContext /*!*/ context, object /*!*/ obj) { if (context.IsObjectFrozen(obj)) { throw RubyExceptions.CreateTypeError("can't modify frozen object"); } }
public static object InitializeCopy(RubyContext/*!*/ context, object self, object source) { RubyClass selfClass = context.GetClassOf(self); RubyClass sourceClass = context.GetClassOf(source); if (sourceClass != selfClass) { throw RubyExceptions.CreateTypeError("initialize_copy should take same class object"); } if (context.IsObjectFrozen(self)) { throw RubyExceptions.CreateTypeError(String.Format("can't modify frozen {0}", selfClass.Name)); } return self; }
public static bool Frozen(RubyContext/*!*/ context, object self) { if (RubyUtils.IsRubyValueType(self)) { return false; // can't freeze value types } return context.IsObjectFrozen(self); }
public static IList UniqueSelf(RubyContext/*!*/ context, IList/*!*/ self) { var seen = new Dictionary<object, bool>(context.EqualityComparer); bool modified = false; int i = 0; while (i < self.Count) { object key = self[i]; if (!seen.ContainsKey(key)) { seen.Add(key, true); i++; } else { if (context.IsObjectFrozen(self)) { throw RubyExceptions.CreateTypeError("can't modify frozen array"); } self.RemoveAt(i); modified = true; } } return modified ? self : null; }
public static void RequiresNotFrozen(RubyContext/*!*/ context, object/*!*/ obj) { if (context.IsObjectFrozen(obj)) { throw RubyExceptions.CreateTypeError("can't modify frozen object"); } }