Object
A Requirement is a set of one or more
version restrictions. It supports a few (=, !=, >, <, >=,
<=, ~>) different restriction operators.
Factory method to create a Gem::Requirement object. Input may be a Version, a String, or nil. Intended to simplify client code.
If the input is “weird”, the default version requirement is returned.
# File rubygems/requirement.rb, line 30
def self.create input
case input
when Gem::Requirement then
input
when Gem::Version, Array then
new input
else
if input.respond_to? :to_str then
new [input.to_str]
else
default
end
end
end
A default “version requirement” can surely only be ‘>= 0’.
# File rubygems/requirement.rb, line 52
def self.default
new '>= 0'
end
Constructs a requirement from requirements. Requirements can
be Strings, Gem::Versions, or Arrays of those. nil and
duplicate requirements are ignored. An empty set of
requirements is the same as ">= 0".
# File rubygems/requirement.rb, line 90
def initialize *requirements
requirements = requirements.flatten
requirements.compact!
requirements.uniq!
requirements << ">= 0" if requirements.empty?
@none = (requirements == ">= 0")
@requirements = requirements.map! { |r| self.class.parse r }
end
Parse obj, returning an [op, version] pair.
obj can be a String or a Gem::Version.
If obj is a String, it can be either a full requirement
specification, like ">= 1.2", or a simple version
number, like "1.2".
parse("> 1.0") # => [">", "1.0"] parse("1.0") # => ["=", "1.0"] parse(Gem::Version.new("1.0")) # => ["=, "1.0"]
# File rubygems/requirement.rb, line 68
def self.parse obj
return ["=", obj] if Gem::Version === obj
unless PATTERN =~ obj.to_s
raise ArgumentError, "Illformed requirement [#{obj.inspect}]"
end
[$1 || "=", Gem::Version.new($2)]
end
# File rubygems/requirement.rb, line 100
def none?
@none ||= (to_s == ">= 0")
end
# File rubygems/requirement.rb, line 120
def prerelease?
requirements.any? { |r| r.last.prerelease? }
end
True if version satisfies this Requirement.
# File rubygems/requirement.rb, line 133
def satisfied_by? version
requirements.all? { |op, rv| OPS[op].call version, rv }
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.