Пример #1
0
        static internal void Init(NetRuby rb)
        {
            RHashClass hash = new RHashClass(rb);

            hash.DefineClass("Hash", rb.cObject);
            IncludeModule(hash, rb.mEnumerable);
            rb.cHash = hash;
            hash.DefineSingletonMethod("new", new RMethod(s_new), -1);
            hash.DefineSingletonMethod("[]", new RMethod(s_create), -1);

            hash.DefineMethod("rehash", new RMethod(s_noop), 0);
            hash.DefineMethod("to_hash", new RMethod(s_noop), 0);

            hash.DefineMethod("[]", new RMethod(aref), 1);
            hash.DefineMethod("[]=", new RMethod(aset), 2);
            hash.DefineMethod("store", new RMethod(aset), 2);
            hash.DefineMethod("default", new RMethod(defaultv), 0);
            hash.DefineMethod("default=", new RMethod(set_default), 1);
            hash.DefineMethod("index", new RMethod(index), 1);
            hash.DefineMethod("indexes", new RMethod(indices), -1);
            hash.DefineMethod("indices", new RMethod(indices), -1);
            hash.DefineMethod("size", new RMethod(size), 0);
            hash.DefineMethod("length", new RMethod(size), 0);
            hash.DefineMethod("empty?", new RMethod(empty_p), 0);

            hash.DefineMethod("each", new RMethod(each_pair), 0);
            hash.DefineMethod("each_value", new RMethod(each_value), 0);
            hash.DefineMethod("each_key", new RMethod(each_key), 0);
            hash.DefineMethod("each_pair", new RMethod(each_pair), 0);
            hash.DefineMethod("sort", new RMethod(sort), 0);

            hash.DefineMethod("keys", new RMethod(keys), 0);
            hash.DefineMethod("values", new RMethod(values), 0);

            hash.DefineMethod("include?", new RMethod(contains_key), 1);
            hash.DefineMethod("member?", new RMethod(contains_key), 1);
            hash.DefineMethod("has_key?", new RMethod(contains_key), 1);
            hash.DefineMethod("key?", new RMethod(contains_key), 1);
            hash.DefineMethod("has_value?", new RMethod(contains_value), 1);
            hash.DefineMethod("value?", new RMethod(contains_value), 1);
        }
Пример #2
0
        static internal void Init(NetRuby rb)
        {
            RHashClass hash = new RHashClass(rb);
            hash.DefineClass("Hash", rb.cObject);
            IncludeModule(hash, rb.mEnumerable);
            rb.cHash = hash;
            hash.DefineSingletonMethod("new", new RMethod(s_new), -1);
            hash.DefineSingletonMethod("[]", new RMethod(s_create), -1);
        
            hash.DefineMethod("rehash", new RMethod(s_noop), 0);
            hash.DefineMethod("to_hash", new RMethod(s_noop), 0);

            hash.DefineMethod("[]", new RMethod(aref), 1);
            hash.DefineMethod("[]=", new RMethod(aset), 2);
            hash.DefineMethod("store", new RMethod(aset), 2);
            hash.DefineMethod("default", new RMethod(defaultv), 0);
            hash.DefineMethod("default=", new RMethod(set_default), 1);
            hash.DefineMethod("index", new RMethod(index), 1);
            hash.DefineMethod("indexes", new RMethod(indices), -1);
            hash.DefineMethod("indices", new RMethod(indices), -1);
            hash.DefineMethod("size", new RMethod(size), 0);
            hash.DefineMethod("length", new RMethod(size), 0);
            hash.DefineMethod("empty?", new RMethod(empty_p), 0);

            hash.DefineMethod("each", new RMethod(each_pair), 0);
            hash.DefineMethod("each_value", new RMethod(each_value), 0);
            hash.DefineMethod("each_key", new RMethod(each_key), 0);
            hash.DefineMethod("each_pair", new RMethod(each_pair), 0);
            hash.DefineMethod("sort", new RMethod(sort), 0);

            hash.DefineMethod("keys", new RMethod(keys), 0);
            hash.DefineMethod("values", new RMethod(values), 0);

            hash.DefineMethod("include?", new RMethod(contains_key), 1);
            hash.DefineMethod("member?", new RMethod(contains_key), 1);
            hash.DefineMethod("has_key?", new RMethod(contains_key), 1);
            hash.DefineMethod("key?", new RMethod(contains_key), 1);
            hash.DefineMethod("has_value?", new RMethod(contains_value), 1);
            hash.DefineMethod("value?", new RMethod(contains_value), 1);
        
        }