In Files

  • rubygems/requirement.rb

Class/Module Index [+]





Public Class Methods

create(input) click to toggle source

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 39
def self.create input
  case input
  when Gem::Requirement then
  when Gem::Version, Array then
    new input
    if input.respond_to? :to_str then
      new [input.to_str]
default() click to toggle source

A default “version requirement” can surely only be ‘>= 0’.

               # File rubygems/requirement.rb, line 61
def self.default
  new '>= 0'
new(*requirements) click to toggle source

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 99
def initialize *requirements
  requirements = requirements.flatten

  requirements << ">= 0" if requirements.empty?
  @none = (requirements == ">= 0")
  @requirements =! { |r| self.class.parse r }
parse(obj) click to toggle source

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("1.0")) # => ["=,  "1.0"]
               # File 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}]"

  [$1 || "=",$2)]

Public Instance Methods

===(version) click to toggle source
Alias for: satisfied_by?
=~(version) click to toggle source
Alias for: satisfied_by?
none?() click to toggle source
               # File rubygems/requirement.rb, line 109
def none?
  @none ||= (to_s == ">= 0")
prerelease?() click to toggle source
               # File rubygems/requirement.rb, line 145
def prerelease?
  requirements.any? { |r| r.last.prerelease? }
satisfied_by?(version) click to toggle source

True if version satisfies this Requirement.

               # File 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 }
Also aliased as: ===, =~
specific?() click to toggle source

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

               # File 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

Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.

If you are posting code samples in your comments, please wrap them in "<pre><code class="ruby" > ... </code></pre>" markup in order to get syntax highlighting.

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 a bug report so that it can be corrected for the next release. Thank you.

blog comments powered by Disqus