summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-16 06:43:43 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-16 06:43:43 +0000
commitd736eded9d4cb7ab5ddc693059d55f8d1e369c98 (patch)
treece1ca9beb8c7219979490076e1f025c360df3cf7 /lib/set.rb
parent8fef6aa20bd658d90036287caa96b9ca17ef3fc5 (diff)
* lib/set.rb (#>=, #>, #<=, #<): Make use of Hash#>=, #>, #<, and
#<= when comparing against an instance of the same kind. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb44
1 files changed, 32 insertions, 12 deletions
diff --git a/lib/set.rb b/lib/set.rb
index d612fdc..17775b0 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -220,33 +220,53 @@ class Set
# Returns true if the set is a superset of the given set.
def superset?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- return false if size < set.size
- set.all? { |o| include?(o) }
+ case
+ when set.instance_of?(self.class)
+ @hash >= set.instance_variable_get(:@hash)
+ when set.is_a?(Set)
+ size >= set.size && set.all? { |o| include?(o) }
+ else
+ raise ArgumentError, "value must be a set"
+ end
end
alias >= superset?
# Returns true if the set is a proper superset of the given set.
def proper_superset?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- return false if size <= set.size
- set.all? { |o| include?(o) }
+ case
+ when set.instance_of?(self.class)
+ @hash > set.instance_variable_get(:@hash)
+ when set.is_a?(Set)
+ size > set.size && set.all? { |o| include?(o) }
+ else
+ raise ArgumentError, "value must be a set"
+ end
end
alias > proper_superset?
# Returns true if the set is a subset of the given set.
def subset?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- return false if set.size < size
- all? { |o| set.include?(o) }
+ case
+ when set.instance_of?(self.class)
+ @hash <= set.instance_variable_get(:@hash)
+ when set.is_a?(Set)
+ size <= set.size && all? { |o| set.include?(o) }
+ else
+ raise ArgumentError, "value must be a set"
+ end
end
alias <= subset?
# Returns true if the set is a proper subset of the given set.
def proper_subset?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- return false if set.size <= size
- all? { |o| set.include?(o) }
+ case
+ when set.instance_of?(self.class)
+ @hash < set.instance_variable_get(:@hash)
+ when set.is_a?(Set)
+ size < set.size && all? { |o| set.include?(o) }
+ else
+ raise ArgumentError, "value must be a set"
+ end
end
alias < proper_subset?