Beispiel #1
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));
        }
Beispiel #2
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);
        }
Beispiel #3
0
 public static Hash /*!*/ CreateSubclass(RubyClass /*!*/ self)
 {
     return(Hash.CreateInstance(self));
 }
Beispiel #4
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));
 }