Methods
#
C
D
N
P
S
Included Modules
Constants
OPS = { #:nodoc: "=" => lambda { |v, r| v == r }, "!=" => lambda { |v, r| v != r }, ">" => lambda { |v, r| v > r }, "<" => lambda { |v, r| v < r }, ">=" => lambda { |v, r| v >= r }, "<=" => lambda { |v, r| v <= r }, "~>" => lambda { |v, r| v >= r && v.release < r.bump } }
 
PATTERN = /\A\s*(#{quoted})?\s*(#{Gem::Version::VERSION_PATTERN})\s*\z/
 
Class Public methods
create(input)

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 lib/rubygems/requirement.rb, line 39
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
default()

A default “version requirement” can surely onlybe '>= 0'.

# File lib/rubygems/requirement.rb, line 61
def self.default
  new '>= 0'
end
new(*requirements)

Constructs a requirement from requirements. Requirements can be Strings, Gem::Versions, or Arrays of those. niland duplicate requirements are ignored. An empty set of requirementsis the same as ">= 0".

# File lib/rubygems/requirement.rb, line 99
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)

Parse obj, returning an [op, version]pair. objcan be a String or a Gem::Version.

If objis 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 lib/rubygems/requirement.rb, line 77
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
Instance Public methods
===(version)
=~(version)
none?()
# File lib/rubygems/requirement.rb, line 109
def none?
  @none ||= (to_s == ">= 0")
end
prerelease?()
# File lib/rubygems/requirement.rb, line 145
def prerelease?
  requirements.any? { |r| r.last.prerelease? }
end
satisfied_by?(version)

True if versionsatisfies this Requirement.

Also aliased as: ===, =~
# File lib/rubygems/requirement.rb, line 158
def satisfied_by? version
  # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey
  requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv }
end
specific?()

True if the requirement will not always match the latest version.

# File lib/rubygems/requirement.rb, line 169
def specific?
  return true if @requirements.length > 1 # GIGO, > 1, > 2 is silly

  not %w[> >=].include? @requirements.first.first # grab the operator
end