public override object Call2(Class last_class, object recv, Frame caller, Proc block, object param0, object val) { Hash hash = ((Hash)recv); Hash.rb_hash_modify(caller, hash); Dictionary.Key key = new Dictionary.Key(param0); hash.value[key] = val; ((Hash)recv).value[new Dictionary.Key(param0)] = val; return val; }
public override object Call0(Class last_class, object recv, Frame caller, Proc block) { Hash hash = (Hash)recv; Dictionary dict = hash.value; // Don't lock the original dictionary. Dictionary.Key[] keys = new Dictionary.Key[dict.Count]; dict.Keys.CopyTo(keys, 0); foreach (Dictionary.Key key in keys) { Proc.rb_yield(block, caller, key.key); if (!object.ReferenceEquals(hash.value, dict)) throw new RuntimeError("rehash occurred during iteration").raise(caller); } return recv; }
public override object Call0(Class last_class, object recv, Frame caller, Proc block) { ArrayList ary = ((Array)recv).value; int count = ary.Count; Dictionary passed = new Dictionary(); for (int i = 0; i < ary.Count; i++) { object o = ary[i]; Dictionary.Key key = new Dictionary.Key(o); if (passed.ContainsKey(key)) { ary.RemoveAt(i); i--; } else { passed.Add(key, null); } } if (count == ary.Count) return null; else return recv; }
public override object Call1(Class last_class, object recv, Frame caller, Proc block, object param0) { Hash hash = (Hash)recv; Hash.rb_hash_modify(caller, hash); Dictionary.Key key = new Dictionary.Key(param0); Dictionary dict = hash.value; object value; if (dict.TryGetValue(key, out value)) { dict.Remove(key); return value; } else if (block != null) { return Proc.rb_yield(block, caller, param0); } else { return null; } }
public override object Call1(Class last_class, object recv, Frame caller, Proc block, object param0) { ArrayList ary = ((Array)recv).value; ArrayList ary2 = Array.ArrayValue(param0, caller); ArrayList result = new ArrayList(ary.Count); Dictionary set = new Dictionary(); for (int i = 0; i < ary.Count; i++) { Dictionary.Key key = new Dictionary.Key(ary[i]); if (!set.ContainsKey(key)) { set.Add(key, null); result.Add(ary[i]); } } for (int i = 0; i < ary2.Count; i++) { Dictionary.Key key = new Dictionary.Key(ary2[i]); if (!set.ContainsKey(key)) { set.Add(key, null); result.Add(ary2[i]); } } return Array.CreateUsing(result); }