Project

General

Profile

Bug #3192 ยป set_keep_if.patch

marcandre (Marc-Andre Lafortune), 04/23/2010 02:40 PM

View differences:

NEWS
* 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.
lib/set.rb
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__)
......
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)
    (1-1/1)