ruby-changes:16136
From: marcandre <ko1@a...>
Date: Sun, 30 May 2010 22:15:32 +0900 (JST)
Subject: [ruby-changes:16136] Ruby:r28095 (ruby_1_9_2): * lib/set.rb (keep_if, select!): New methods
marcandre 2010-05-30 22:15:17 +0900 (Sun, 30 May 2010) New Revision: 28095 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28095 Log: * lib/set.rb (keep_if, select!): New methods [ruby-core:29749] Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/NEWS branches/ruby_1_9_2/lib/set.rb Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 28094) +++ ruby_1_9_2/ChangeLog (revision 28095) @@ -1,3 +1,7 @@ +Sun May 30 22:14:14 2010 Marc-Andre Lafortune <ruby-core@m...> + + * lib/set.rb (keep_if, select!): New methods [ruby-core:29749] + Sun May 30 19:17:31 2010 NARUSE, Yui <naruse@r...> * ext/nkf/nkf-utf8/nkf.c: updated to b856dd07. Index: ruby_1_9_2/lib/set.rb =================================================================== --- ruby_1_9_2/lib/set.rb (revision 28094) +++ ruby_1_9_2/lib/set.rb (revision 28095) @@ -266,6 +266,14 @@ self end + # Deletes every element of the set for which block evaluates to + # false, and returns self. + def keep_if + block_given? or return enum_for(__method__) + to_a.each { |o| @hash.delete(o) unless yield(o) } + self + end + # Replaces the elements with ones returned by collect(). def collect! block_given? or return enum_for(__method__) @@ -284,6 +292,15 @@ size == n ? nil : self end + # Equivalent to Set#keep_if, but returns nil if no changes were + # made. + def select! + block_given? or return enum_for(__method__) + n = size + keep_if { |o| yield(o) } + size == n ? nil : self + end + # Merges the elements of the given enumerable object to the set and # returns self. def merge(enum) @@ -563,6 +580,14 @@ self end + def keep_if + block_given? or return enum_for(__method__) + n = @hash.size + super + @keys = nil if @hash.size != n + self + end + def merge(enum) @keys = nil super Index: ruby_1_9_2/NEWS =================================================================== --- ruby_1_9_2/NEWS (revision 28094) +++ ruby_1_9_2/NEWS (revision 28095) @@ -373,6 +373,11 @@ * Readline.completion_proc= accepts nil. nil means to use default completion proc. +* set + * new methods: + * Set#keep_if + * Set#select! + * time * incompatible changes: * Time.parse raises ArgumentError when no date information. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/