diff --git a/ChangeLog b/ChangeLog index 4a1075fbfe..631bbbf838 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Aug 31 17:38:43 2012 Akinori MUSHA + + * 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 * lib/ipaddr.rb: Introduce several new error classes where only diff --git a/lib/set.rb b/lib/set.rb index 9727ba3b3c..19bb892feb 100755 --- a/lib/set.rb +++ b/lib/set.rb @@ -228,9 +228,9 @@ class Set # 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 @@ class Set # 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 @@ class SortedSet < Set 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