Logo
Explore Help
Sign In
mirrors/brew
1
0
Fork 0
You've already forked brew
mirror of https://github.com/Homebrew/brew.git synced 2025-07-14 16:09:03 +08:00
Code Issues Packages Projects Releases Wiki Activity
brew/Library/Homebrew/extend/set.rb

26 lines
538 B
Ruby
Raw Normal View History

Manage Requirements using ComparableSet ComparableSet only allows a single object of a given class, choosing the object with the greatest value. This was mainly created for Requirements, so that, e.g., two X11Dependencies of differing strictness don't both end up in the same requirement set. Fixes Homebrew/homebrew#15240.
2012-10-02 13:21:00 -05:00
require 'set'
class ComparableSet < Set
def add new
# smileys only
return super new unless new.respond_to? :>
objs = find_all { |o| o.class == new.class }
objs.each do |o|
return self if o > new
delete o
end
super new
end
alias_method :<<, :add
# Set#merge bypasses enumerating the set's contents,
# so the subclassed #add would never be called
def merge enum
enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable"
enum.each { |o| add(o) }
ComparableSet#merge returns self Set#merge is supposed to return self, and Formula#recursive_requirements depended on this being true. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
2012-10-25 15:45:42 -05:00
self
Manage Requirements using ComparableSet ComparableSet only allows a single object of a given class, choosing the object with the greatest value. This was mainly created for Requirements, so that, e.g., two X11Dependencies of differing strictness don't both end up in the same requirement set. Fixes Homebrew/homebrew#15240.
2012-10-02 13:21:00 -05:00
end
end
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.8 Page: 38ms Template: 4ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API