class Gem::NameTuple
表示一个具有 name
名称、version
版本和 platform
平台的 gem。 这些封装了从索引返回的数据。
属性
公共类方法
源代码
# File lib/rubygems/name_tuple.rb, line 24 def self.from_list(list) list.map {|t| new(*t) } end
将 [name, version, platform] 数组转换为 NameTuple
对象数组。
源代码
# File lib/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
源代码
# File lib/rubygems/name_tuple.rb, line 39 def self.null new nil, Gem::Version.new(0), nil end
一个空的 NameTuple
,即 name=nil,version=0
源代码
# File lib/rubygems/name_tuple.rb, line 32 def self.to_basic(list) list.map(&:to_a) end
将 NameTuple
对象数组转换回
- name, version, platform
-
元组数组。
公共实例方法
源代码
# File lib/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
源代码
# File lib/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
与 other
进行比较。支持另一个 NameTuple
或一个 [name, version, platform] 格式的 Array
。
也别名为: eql?
源代码
# File lib/rubygems/name_tuple.rb, line 48 def full_name case @platform when nil, "", Gem::Platform::RUBY "#{@name}-#{@version}" else "#{@name}-#{@version}-#{@platform}" end end
返回此 Gem
的完整名称(名称-版本)。如果不是默认的 Ruby 平台,则包含平台信息。这模仿了 Gem::Specification#full_name
的行为。
源代码
# File lib/rubygems/name_tuple.rb, line 60 def match_platform? Gem::Platform.match_gem? @platform, @name end
指示此 NameTuple
是否与当前平台匹配。
源代码
# File lib/rubygems/name_tuple.rb, line 66 def prerelease? @version.prerelease? end
指示此 NameTuple
是否用于预发布版本。
源代码
# File lib/rubygems/name_tuple.rb, line 73 def spec_name "#{full_name}.gemspec" end
返回 gemspec 文件将使用的名称
源代码
# File lib/rubygems/name_tuple.rb, line 80 def to_a [@name, @version, @platform] end
转换回 [name, version, platform] 元组