From a46eacb213bbf001f688dc8f00cf85ea1b8a6281 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Wed, 8 May 2013 11:58:46 +0900 Subject: Move Hash#values_at to mruby-hash-ext gem. --- mrbgems/mruby-hash-ext/src/hash-ext.c | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 mrbgems/mruby-hash-ext/src/hash-ext.c (limited to 'mrbgems/mruby-hash-ext/src') diff --git a/mrbgems/mruby-hash-ext/src/hash-ext.c b/mrbgems/mruby-hash-ext/src/hash-ext.c new file mode 100644 index 000000000..94518924e --- /dev/null +++ b/mrbgems/mruby-hash-ext/src/hash-ext.c @@ -0,0 +1,62 @@ +/* +** hash.c - Hash class +** +** See Copyright Notice in mruby.h +*/ + +#include "mruby.h" +#include "mruby/array.h" +#include "mruby/class.h" +#include "mruby/hash.h" +#include "mruby/khash.h" +#include "mruby/string.h" +#include "mruby/variable.h" + +/* + * call-seq: + * hsh.values_at(key, ...) -> array + * + * Return an array containing the values associated with the given keys. + * Also see Hash.select. + * + * h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" } + * h.values_at("cow", "cat") #=> ["bovine", "feline"] + */ + +mrb_value +mrb_hash_values_at(mrb_state *mrb, int argc, mrb_value *argv, mrb_value hash) +{ + mrb_value result = mrb_ary_new_capa(mrb, argc); + long i; + + for (i=0; ihash_class; + + mrb_define_method(mrb, h, "values_at", hash_values_at, MRB_ARGS_ANY()); +} + +void +mrb_mruby_hash_ext_gem_final(mrb_state *mrb) +{ +} -- cgit v1.2.3