ruby-changes:24818
From: knu <ko1@a...>
Date: Fri, 31 Aug 2012 17:43:20 +0900 (JST)
Subject: [ruby-changes:24818] knu:r36869 (trunk): * lib/set.rb (Set#{each,reject!,select!}, SortedSet#each): Pass
knu 2012-08-31 17:43:09 +0900 (Fri, 31 Aug 2012) New Revision: 36869 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36869 Log: * lib/set.rb (Set#{each,reject!,select!}, SortedSet#each): Pass the original block through instead of creating one that only yields the passed argument. Modified files: trunk/ChangeLog trunk/lib/set.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 36868) +++ ChangeLog (revision 36869) @@ -1,3 +1,9 @@ +Fri Aug 31 17:38:43 2012 Akinori MUSHA <knu@i...> + + * lib/set.rb (Set#{each,reject!,select!}, SortedSet#each): Pass + the original block through instead of creating one that only + yields the passed argument. + Fri Aug 31 16:23:20 2012 Akinori MUSHA <knu@i...> * lib/ipaddr.rb: Introduce several new error classes where only Index: lib/set.rb =================================================================== --- lib/set.rb (revision 36868) +++ lib/set.rb (revision 36869) @@ -228,9 +228,9 @@ # Calls the given block once for each element in the set, passing # the element as parameter. Returns an enumerator if no block is # given. - def each - block_given? or return enum_for(__method__) - @hash.each_key { |o| yield(o) } + def each(&block) + block or return enum_for(__method__) + @hash.each_key(&block) self end @@ -296,19 +296,19 @@ # Equivalent to Set#delete_if, but returns nil if no changes were # made. - def reject! - block_given? or return enum_for(__method__) + def reject!(&block) + block or return enum_for(__method__) n = size - delete_if { |o| yield(o) } + delete_if(&block) 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__) + def select!(&block) + block or return enum_for(__method__) n = size - keep_if { |o| yield(o) } + keep_if(&block) size == n ? nil : self end @@ -603,9 +603,9 @@ super end - def each - block_given? or return enum_for(__method__) - to_a.each { |o| yield(o) } + def each(&block) + block or return enum_for(__method__) + to_a.each(&block) self end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/