Ruby 4.1 リファレンスマニュアル

class Gem::Dependency

[edit]

要約

Gem の依存関係を管理するクラスです。

目次

インスタンスメソッド
定数

インスタンスメソッド

self <=> other -> IntegerRuby 1.9.3 から[permalink][rdoc][edit]

self と other を Gem::Dependency#name の ASCII コードで比較して self が大きい時には正の整数、等しい時には 0、小さい時には負の整数を返します。

self =~ other -> boolRuby 1.9.3 から[permalink][rdoc][edit]
self === other -> bool

self と other を比較して真偽値を返します。

self の Gem::Dependency#name が正規表現として other とマッチしない場合は偽を返します。 self が other との依存関係を満たしていれば真を返します。満たしていなければ偽を返します。

identity -> SymbolRuby 2.7.0 から[permalink][rdoc][edit]

self の依存関係の種類を表すシンボルを返します。

self がプレリリース版を要求しており、かつ Gem::Dependency#specific? が真であれば :complete を、プレリリース版を要求しているが specific? が偽であれば :abs_latest を返します。プレリリース版を要求しておらず、Gem::Dependency#latest_version? が真であれば :latest を、それ以外の場合は :released を返します。

例
p Gem::Dependency.new("rake").identity           # => :latest
p Gem::Dependency.new("rake", ">= 1.0").identity # => :released

[SEE_ALSO] Gem::Dependency#prerelease?, Gem::Dependency#specific?, Gem::Dependency#latest_version?

latest_version? -> boolRuby 2.0.0 から[permalink][rdoc][edit]

self が単に最新のバージョンを要求しているだけかどうかを返します。

Gem::Dependency#requirement が条件を持たない(Gem::Requirement#none? が真である)場合に true を返します。

match?(obj, version = nil, allow_prerelease = false) -> boolRuby 1.9.2 から[permalink][rdoc][edit]

self が指定した Gem やスペックにマッチするかどうかを返します。

version を省略した場合、obj には name と version に応答するオブジェクト (Gem::Specification など)を指定します。version を指定した場合は、 obj には Gem の名前を文字列で指定します。

[PARAM] obj:
version を省略する場合は name・version に応答するオブジェクトを、指定する場合は Gem の名前を表す文字列を指定します。
[PARAM] version:
obj のバージョンを表す文字列を指定します。省略できます。
[PARAM] allow_prerelease:
obj のバージョンがプレリリース版であってもマッチを許可するかどうかを true か false で指定します。
[RETURN]
self の Gem::Dependency#name が一致せず、またはバージョンが self の条件を満たさない場合は false を返します。マッチする場合は true を返します。
例
dep = Gem::Dependency.new("rake", "~> 1.0")
p dep.match?("rake", "1.0.1") # => true
p dep.match?("rake", "2.0.0") # => false

spec = Gem::Specification.new("rake", "1.0.1")
p dep.match?(spec)            # => true

[SEE_ALSO] Gem::Dependency#matches_spec?

matches_spec?(spec) -> boolRuby 1.9.3 から[permalink][rdoc][edit]

self が spec にマッチするかどうかを返します。

Gem::Dependency#name が spec の名前と一致せず、または spec のバージョンが self の条件を満たさない場合は false を返します。Gem::Dependency#match? と異なり、self がプレリリース版を要求していなくても、spec 自体がプレリリース版であれば true を返すことがあります。

[PARAM] spec:
マッチさせたい Gem::Specification のインスタンスを指定します。
例
dep = Gem::Dependency.new("rake", "~> 1.0")

spec1 = Gem::Specification.new("rake", "1.0.1")
p dep.matches_spec?(spec1) # => true

spec2 = Gem::Specification.new("rake", "2.0.0")
p dep.matches_spec?(spec2) # => false

[SEE_ALSO] Gem::Dependency#match?

matching_specs(platform_only = false) -> [Gem::Specification]Ruby 1.9.3 から[permalink][rdoc][edit]

self の Gem::Dependency#name と Gem::Dependency#requirement を満たす、インストール済みの Gem::Specification を配列で返します。

platform_only に true を指定すると、さらに現在のプラットフォームにインストール可能なものだけに絞り込みます。無効化された(ignored? な)スペックは結果に含まれません。

[PARAM] platform_only:
true を指定すると、現在のプラットフォームにインストール可能なスペックだけに絞り込みます。
merge(other) -> Gem::DependencyRuby 1.9.3 から[permalink][rdoc][edit]

self と other の条件をマージした、新しい Gem::Dependency を返します。

other の Gem::Dependency#requirement が Gem::Requirement.default と等しい場合は self の条件を、self の条件が Gem::Requirement.default と等しい場合は other の条件を、それ以外の場合は両方の条件を連結したものを持つ、新しい Gem::Dependency を返します。

[PARAM] other:
マージする Gem::Dependency を指定します。
[EXCEPTION] ArgumentError:
self と other の Gem::Dependency#name が異なる場合に発生します。
例
dep1 = Gem::Dependency.new("rake", "< 5.0")
dep2 = Gem::Dependency.new("rake", ">= 1.9")
p dep1.merge(dep2)
# => <Gem::Dependency type=:runtime name="rake" requirements="< 5.0, >= 1.9">
name -> StringRuby 1.9.3 から[permalink][rdoc][edit]

依存関係の名前を文字列か正規表現で返します。

name=(name)Ruby 1.9.3 から[permalink][rdoc][edit]

依存関係の名前を文字列か正規表現でセットします。

prerelease=(prerelease)Ruby 1.9.2 から[permalink][rdoc][edit]

self を強制的にプレリリース版の依存関係として扱うかどうかを設定します。

[PARAM] prerelease:
プレリリース版として扱うかどうかを true か false で指定します。

[SEE_ALSO] Gem::Dependency#prerelease?

prerelease? -> boolRuby 1.9.2 から[permalink][rdoc][edit]

self がプレリリース版を要求するかどうかを返します。

Gem::Dependency#prerelease= で明示的に true が設定されているか、 Gem::Dependency#requirement が Gem::Requirement#prerelease? を満たす場合に true を返します。

例
dep = Gem::Dependency.new("rake", ">= 1.0")
p dep.prerelease?    # => false

dep.prerelease = true
p dep.prerelease?    # => true
requirement -> Gem::RequirementRuby 1.9.2 から[permalink][rdoc][edit]

self が要求するバージョンの条件を、Gem::Requirement のインスタンスで返します。

例
dep = Gem::Dependency.new("rake", "= 1.0")
pp dep.requirement
# => Gem::Requirement.new(["= 1.0"])
requirements_list -> [String]Ruby 1.9.3 から[permalink][rdoc][edit]

バージョンの必要条件を文字列の配列として返します。

runtime? -> boolRuby 2.3.0 から[permalink][rdoc][edit]

self の Gem::Dependency#type が :runtime かどうかを返します。

type が明示的に設定されていない場合も true を返します。

例
p Gem::Dependency.new("rake", ">= 1.0").runtime?               # => true
p Gem::Dependency.new("rake", ">= 1.0", :development).runtime? # => false
specific? -> boolRuby 1.9.3 から[permalink][rdoc][edit]

self の条件が、常に最新バージョンにマッチするとは限らない場合に true を返します。

Gem::Dependency#requirement の Gem::Requirement#specific? の結果をそのまま返します。

例
p Gem::Dependency.new("rake", ">= 1.0").specific? # => false
p Gem::Dependency.new("rake", "= 1.0").specific?  # => true
to_spec -> Gem::SpecificationRuby 1.9.3 から[permalink][rdoc][edit]

self の条件を満たす、インストール済みの Gem::Specification を 1 つ返します。

Gem::Dependency#to_specs が返す候補の中から、既にロードされている(activated? な) ものを優先して返します。self が Gem::Dependency#prerelease? でなければ、プレリリース版は他に候補が無いときだけ選ばれます。

[SEE_ALSO] Gem::Dependency#to_specs

to_specs -> [Gem::Specification]Ruby 1.9.3 から[permalink][rdoc][edit]

self の条件を満たす、インストール済みの Gem::Specification を配列で返します。

[EXCEPTION] Gem::MissingSpecError:
条件を満たすスペックが見つからず、同名のスペックも全く無い場合に発生します。
[EXCEPTION] Gem::MissingSpecVersionError:
同名のスペックは存在するものの、条件を満たすバージョンのものが無い場合に発生します。

[SEE_ALSO] Gem::Dependency#to_spec, Gem::Dependency#matching_specs

type -> SymbolRuby 1.9.3 から[permalink][rdoc][edit]

依存関係の型を返します。

定数

TYPES -> ArrayRuby 1.9.3 から[permalink][rdoc][edit]

有効な依存関係の型を表す配列です。

[SEE_ALSO] Gem::Specification::CURRENT_SPECIFICATION_VERSION