diff options
-rw-r--r-- | hash.c | 141 |
1 files changed, 104 insertions, 37 deletions
@@ -2504,20 +2504,43 @@ rb_hash_delete(VALUE hash, VALUE key) /* * call-seq: - * hsh.delete(key) -> value - * hsh.delete(key) {| key | block } -> value * - * Deletes the key-value pair and returns the value from <i>hsh</i> whose - * key is equal to <i>key</i>. If the key is not found, it returns - * <em>nil</em>. If the optional code block is given and the - * key is not found, pass in the key and return the result of - * <i>block</i>. * - * h = { "a" => 100, "b" => 200 } - * h.delete("a") #=> 100 - * h.delete("z") #=> nil - * h.delete("z") { |el| "#{el} not found" } #=> "z not found" * */ static VALUE @@ -2558,15 +2581,19 @@ shift_i_safe(VALUE key, VALUE value, VALUE arg) /* * call-seq: - * hsh.shift -> anArray or obj * - * Removes a key-value pair from <i>hsh</i> and returns it as the - * two-item array <code>[</code> <i>key, value</i> <code>]</code>, or - * the hash's default value if the hash is empty. * - * h = { 1 => "a", 2 => "b", 3 => "c" } - * h.shift #=> [1, "a"] - * h #=> {2=>"b", 3=>"c"} */ static VALUE @@ -2625,17 +2652,30 @@ hash_enum_size(VALUE hash, VALUE args, VALUE eobj) /* * call-seq: - * hsh.delete_if {| key, value | block } -> hsh - * hsh.delete_if -> an_enumerator * - * Deletes every key-value pair from <i>hsh</i> for which <i>block</i> - * evaluates to <code>true</code>. * - * If no block is given, an enumerator is returned instead. * - * h = { "a" => 100, "b" => 200, "c" => 300 } - * h.delete_if {|key, value| key >= "b" } #=> {"a"=>100} * */ VALUE @@ -2651,11 +2691,34 @@ rb_hash_delete_if(VALUE hash) /* * call-seq: - * hsh.reject! {| key, value | block } -> hsh or nil - * hsh.reject! -> an_enumerator * - * Equivalent to Hash#delete_if, but returns - * <code>nil</code> if no changes were made. */ VALUE @@ -2683,16 +2746,20 @@ reject_i(VALUE key, VALUE value, VALUE result) /* * call-seq: - * hsh.reject {|key, value| block} -> a_hash - * hsh.reject -> an_enumerator * - * Returns a new hash consisting of entries for which the block returns false. - * - * If no block is given, an enumerator is returned instead. * - * h = { "a" => 100, "b" => 200, "c" => 300 } - * h.reject {|k,v| k < "b"} #=> {"b" => 200, "c" => 300} - * h.reject {|k,v| v > 100} #=> {"a" => 100} */ VALUE |