Example #1
0
 public static void RequiresNotFrozen(RubyContext /*!*/ context, object /*!*/ obj)
 {
     if (context.IsObjectFrozen(obj))
     {
         throw RubyExceptions.CreateTypeError("can't modify frozen object");
     }
 }
Example #2
0
        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;
        }
Example #3
0
 public static bool Frozen(RubyContext/*!*/ context, object self) {
     if (RubyUtils.IsRubyValueType(self)) {
         return false; // can't freeze value types
     }
     return context.IsObjectFrozen(self);
 }
Example #4
0
        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;
        }
Example #5
0
 public static void RequiresNotFrozen(RubyContext/*!*/ context, object/*!*/ obj) {
     if (context.IsObjectFrozen(obj)) {
         throw RubyExceptions.CreateTypeError("can't modify frozen object");
     }
 }