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. --- src/hash.c | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'src') diff --git a/src/hash.c b/src/hash.c index da5f49b02..566d423a9 100644 --- a/src/hash.c +++ b/src/hash.c @@ -610,29 +610,6 @@ mrb_hash_shift(mrb_state *mrb, mrb_value hash) * */ -/* - * 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; i a_hash -- cgit v1.2.3 From 82c891acee1c1d2657b3dbe73797af5a7020827f Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Wed, 8 May 2013 12:50:38 +0900 Subject: Move comments from hash.c to hash.rb. --- mrblib/hash.rb | 45 +++++++++++++++++++++++++++++++++++++++++ src/hash.c | 63 ---------------------------------------------------------- 2 files changed, 45 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/mrblib/hash.rb b/mrblib/hash.rb index c304d4845..f7cdbdc6d 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -24,6 +24,23 @@ class Hash # Calls the given block for each element of +self+ # and pass the key and value of each element. # + # call-seq: + # hsh.each {| key, value | block } -> hsh + # hsh.each_pair {| key, value | block } -> hsh + # hsh.each -> an_enumerator + # hsh.each_pair -> an_enumerator + # + # + # If no block is given, an enumerator is returned instead. + # + # h = { "a" => 100, "b" => 200 } + # h.each {|key, value| puts "#{key} is #{value}" } + # + # produces: + # + # a is 100 + # b is 200 + # # ISO 15.2.13.4.9 def each(&block) self.keys.each{|k| block.call([k, self[k]])} @@ -34,6 +51,20 @@ class Hash # Calls the given block for each element of +self+ # and pass the key of each element. # + # call-seq: + # hsh.each_key {| key | block } -> hsh + # hsh.each_key -> an_enumerator + # + # If no block is given, an enumerator is returned instead. + # + # h = { "a" => 100, "b" => 200 } + # h.each_key {|key| puts key } + # + # produces: + # + # a + # b + # # ISO 15.2.13.4.10 def each_key(&block) self.keys.each{|k| block.call(k)} @@ -44,6 +75,20 @@ class Hash # Calls the given block for each element of +self+ # and pass the value of each element. # + # call-seq: + # hsh.each_value {| value | block } -> hsh + # hsh.each_value -> an_enumerator + # + # If no block is given, an enumerator is returned instead. + # + # h = { "a" => 100, "b" => 200 } + # h.each_value {|value| puts value } + # + # produces: + # + # 100 + # 200 + # # ISO 15.2.13.4.11 def each_value(&block) self.keys.each{|k| block.call(self[k])} diff --git a/src/hash.c b/src/hash.c index 566d423a9..6910aec7f 100644 --- a/src/hash.c +++ b/src/hash.c @@ -790,69 +790,6 @@ mrb_hash_empty_p(mrb_state *mrb, mrb_value self) return mrb_bool_value(empty_p); } -/* 15.2.13.4.11 */ -/* - * call-seq: - * hsh.each_value {| value | block } -> hsh - * hsh.each_value -> an_enumerator - * - * Calls block once for each key in hsh, passing the - * value as a parameter. - * - * If no block is given, an enumerator is returned instead. - * - * h = { "a" => 100, "b" => 200 } - * h.each_value {|value| puts value } - * - * produces: - * - * 100 - * 200 - */ - -/* 15.2.13.4.10 */ -/* - * call-seq: - * hsh.each_key {| key | block } -> hsh - * hsh.each_key -> an_enumerator - * - * Calls block once for each key in hsh, passing the key - * as a parameter. - * - * If no block is given, an enumerator is returned instead. - * - * h = { "a" => 100, "b" => 200 } - * h.each_key {|key| puts key } - * - * produces: - * - * a - * b - */ - -/* 15.2.13.4.9 */ -/* - * call-seq: - * hsh.each {| key, value | block } -> hsh - * hsh.each_pair {| key, value | block } -> hsh - * hsh.each -> an_enumerator - * hsh.each_pair -> an_enumerator - * - * Calls block once for each key in hsh, passing the key-value - * pair as parameters. - * - * If no block is given, an enumerator is returned instead. - * - * h = { "a" => 100, "b" => 200 } - * h.each {|key, value| puts "#{key} is #{value}" } - * - * produces: - * - * a is 100 - * b is 200 - * - */ - static mrb_value inspect_hash(mrb_state *mrb, mrb_value hash, int recur) { -- cgit v1.2.3 From c9edc5b02ee07aa2b8caa994910d31273260ca22 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Wed, 8 May 2013 09:42:03 +0900 Subject: Remove mrb_hash_lookup() as no one uses it. Use mrb_hash_get instead. --- src/hash.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src') diff --git a/src/hash.c b/src/hash.c index 6910aec7f..882dd3121 100644 --- a/src/hash.c +++ b/src/hash.c @@ -324,12 +324,6 @@ mrb_hash_aget(mrb_state *mrb, mrb_value self) return mrb_hash_get(mrb, self, key); } -mrb_value -mrb_hash_lookup(mrb_state *mrb, mrb_value hash, mrb_value key) -{ - return mrb_hash_get(mrb, hash, key); -} - /* * call-seq: * hsh.fetch(key [, default] ) -> obj -- cgit v1.2.3