class Gem::NameTuple

表示一个 gem,其名称为 name,版本为 version,平台为 platform。这些封装了从索引返回的数据。

属性

name[R]
platform[R]
version[R]

公共类方法

from_list(list) 点击以切换源代码

将 [名称, 版本, 平台] 的数组转换为 NameTuple 对象的数组。

# File rubygems/name_tuple.rb, line 24
def self.from_list(list)
  list.map {|t| new(*t) }
end
new(name, version, platform=Gem::Platform::RUBY) 点击以切换源代码
# File rubygems/name_tuple.rb, line 9
def initialize(name, version, platform=Gem::Platform::RUBY)
  @name = name
  @version = version

  platform &&= platform.to_s
  platform = Gem::Platform::RUBY if !platform || platform.empty?
  @platform = platform
end
null() 点击以切换源代码

一个空的 NameTuple,即 name=nil, version=0

# File rubygems/name_tuple.rb, line 39
def self.null
  new nil, Gem::Version.new(0), nil
end
to_basic(list) 点击以切换源代码

NameTuple 对象的数组转换回

名称, 版本, 平台

的元组数组。

# File rubygems/name_tuple.rb, line 32
def self.to_basic(list)
  list.map(&:to_a)
end

公共实例方法

<=>(other) 点击以切换源代码
# File rubygems/name_tuple.rb, line 90
def <=>(other)
  [@name, @version, Gem::Platform.sort_priority(@platform)] <=>
    [other.name, other.version, Gem::Platform.sort_priority(other.platform)]
end
==(other) 点击以切换源代码

other 进行比较。支持另一个 NameTuple 或 [name, version, platform] 格式的数组。

# File rubygems/name_tuple.rb, line 101
def ==(other)
  case other
  when self.class
    @name == other.name &&
      @version == other.version &&
      @platform == other.platform
  when Array
    to_a == other
  else
    false
  end
end
也别名为:eql?
eql?(other)
别名为:==
full_name() 点击以切换源代码

返回此 Gem 的完整名称(名称-版本)。如果不是默认的 Ruby 平台,则包含平台信息。这模仿了 Gem::Specification#full_name 的行为。

# File rubygems/name_tuple.rb, line 48
def full_name
  case @platform
  when nil, "", Gem::Platform::RUBY
    "#{@name}-#{@version}"
  else
    "#{@name}-#{@version}-#{@platform}"
  end
end
hash() 点击以切换源代码
# File rubygems/name_tuple.rb, line 116
def hash
  to_a.hash
end
match_platform?() 点击以切换源代码

指示此 NameTuple 是否与当前平台匹配。

# File rubygems/name_tuple.rb, line 60
def match_platform?
  Gem::Platform.match_gem? @platform, @name
end
prerelease?() 点击以切换源代码

指示此 NameTuple 是否为预发布版本。

# File rubygems/name_tuple.rb, line 66
def prerelease?
  @version.prerelease?
end
spec_name() 点击以切换源代码

返回 gemspec 文件将使用的名称

# File rubygems/name_tuple.rb, line 73
def spec_name
  "#{full_name}.gemspec"
end
to_a() 点击以切换源代码

转换回 [name, version, platform] 元组

# File rubygems/name_tuple.rb, line 80
def to_a
  [@name, @version, @platform]
end