From 3422839fd25bfe0ccfed4c27a1d464a4848ac6fd Mon Sep 17 00:00:00 2001 From: Alvaro Pereyra Date: Sat, 8 Oct 2011 17:57:11 -0500 Subject: [PATCH] Improves array examples for uniq/uniq! --- array.c | 20 ++++++++++++++------ 1 files changed, 14 insertions(+), 6 deletions(-) diff --git a/array.c b/array.c index 8816d15..27a1c51 100644 --- a/array.c +++ b/array.c @@ -3509,16 +3509,20 @@ push_value(st_data_t key, st_data_t val, st_data_t ary) * call-seq: * ary.uniq! -> ary or nil * - * Removes duplicate elements from +self+. + * Removes duplicate elements from +self+. If a block is given, + * it will use the return value of the block for comparison. * Returns nil if no changes are made (that is, no * duplicates are found). * * a = [ "a", "a", "b", "b", "c" ] * a.uniq! #=> ["a", "b", "c"] + * * b = [ "a", "b", "c" ] * b.uniq! #=> nil - * c = [ "a:def", "a:xyz", "b:abc", "b:xyz", "c:jkl" ] - * c.uniq! {|s| s[/^\w+/]} #=> [ "a:def", "b:abc", "c:jkl" ] + * + * c = [["student","sam"], ["student","george"], ["teacher","matz"]] + * c.uniq!{ |s| s.first } #=> [["student", "sam"], ["teacher", "matz"]] + * */ static VALUE @@ -3565,12 +3569,16 @@ rb_ary_uniq_bang(VALUE ary) * call-seq: * ary.uniq -> new_ary * - * Returns a new array by removing duplicate values in +self+. + * Returns a new array by removing duplicate values in +self+. If a block + * is given, it will use the return value of that block as the values to + * filter. * * a = [ "a", "a", "b", "b", "c" ] * a.uniq #=> ["a", "b", "c"] - * c = [ "a:def", "a:xyz", "b:abc", "b:xyz", "c:jkl" ] - * c.uniq {|s| s[/^\w+/]} #=> [ "a:def", "b:abc", "c:jkl" ] + * + * b = [["student","sam"], ["student","george"], ["teacher","matz"]] + * b.uniq!{ |s| s.first } #=> [["student", "sam"], ["teacher", "matz"]] + * */ static VALUE -- 1.7.4.4