class RBS::Substitution
属性
instance_type[RW]
mapping[R]
公共类方法
build(variables, types, instance_type: nil) { |t| ... } 点击切换源代码
# File rbs-3.8.0/lib/rbs/substitution.rb, line 20 def self.build(variables, types, instance_type: nil, &block) unless variables.size == types.size raise "Broken substitution: variables=#{variables}, types=#{types}" end mapping = variables.zip(types).to_h self.new.tap do |subst| mapping.each do |v, t| type = block_given? ? yield(t) : t subst.add(from: v, to: type) end subst.instance_type = instance_type end end
new() 点击切换源代码
# File rbs-3.8.0/lib/rbs/substitution.rb, line 12 def initialize() @mapping = {} end
公共实例方法
+(other) 点击切换源代码
# File rbs-3.8.0/lib/rbs/substitution.rb, line 66 def +(other) return self if other.empty? return other if self.empty? Substitution.new.tap do |subst| subst.mapping.merge!(mapping) other.mapping.each do |var, type| if mapping.key?(var) subst.add(from: var, to: self[type]) else subst.add(from: var, to: type) end end end end
add(from:, to:) 点击切换源代码
# File rbs-3.8.0/lib/rbs/substitution.rb, line 16 def add(from:, to:) mapping[from] = to end
apply(ty) 点击切换源代码
# File rbs-3.8.0/lib/rbs/substitution.rb, line 37 def apply(ty) case ty when Types::Variable # @type var ty: Types::Variable mapping[ty.name] || ty when Types::Bases::Instance if t = instance_type t else ty end else ty end end
别名: []
empty?() 点击切换源代码
# File rbs-3.8.0/lib/rbs/substitution.rb, line 8 def empty? mapping.empty? && instance_type.nil? end
without(*vars) 点击切换源代码
# File rbs-3.8.0/lib/rbs/substitution.rb, line 55 def without(*vars) Substitution.new.tap do |subst| subst.mapping.merge!(mapping) vars.each do |var| subst.mapping.delete(var) end subst.instance_type = self.instance_type end end