Class: RBS::AST::Declarations::ModuleTypeParams

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/ast/declarations.rb

Constant Summary collapse

TypeParam =
_ = Struct.new(:name, :variance, :skip_validation, :location, keyword_init: true) do
  # @implements TypeParam

  def to_json(state = _ = nil)
    {
      name: name,
      variance: variance,
      skip_validation: skip_validation,
    }.to_json(state)
  end

  def ==(other)
    other.is_a?(TypeParam) &&
      other.name == name &&
      other.variance == variance &&
      other.skip_validation == skip_validation
  end

  alias eql? ==

  def hash
    self.class.hash ^ name.hash ^ variance.hash ^ skip_validation.hash
  end
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModuleTypeParams

Returns a new instance of ModuleTypeParams.



35
36
37
# File 'lib/rbs/ast/declarations.rb', line 35

def initialize()
  @params = []
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/rbs/ast/declarations.rb', line 8

def params
  @params
end

Class Method Details

.emptyObject



72
73
74
# File 'lib/rbs/ast/declarations.rb', line 72

def self.empty
  new
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



44
45
46
# File 'lib/rbs/ast/declarations.rb', line 44

def ==(other)
  other.is_a?(ModuleTypeParams) && other.params == params
end

#[](name) ⇒ Object



54
55
56
# File 'lib/rbs/ast/declarations.rb', line 54

def [](name)
  params.find {|p| p.name == name }
end

#add(param) ⇒ Object



39
40
41
42
# File 'lib/rbs/ast/declarations.rb', line 39

def add(param)
  params << param
  self
end

#each(&block) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/rbs/ast/declarations.rb', line 64

def each(&block)
  if block
    params.each(&block)
  else
    params.each
  end
end

#empty?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/rbs/ast/declarations.rb', line 86

def empty?
  params.empty?
end

#hashObject



50
51
52
# File 'lib/rbs/ast/declarations.rb', line 50

def hash
  params.hash
end

#rename_to(names) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/rbs/ast/declarations.rb', line 94

def rename_to(names)
  ModuleTypeParams.new().tap do |params|
    names.each.with_index do |new_name, index|
      param = self.params[index]
      params.add(TypeParam.new(name: new_name, variance: param.variance, skip_validation: param.skip_validation, location: param.location))
    end
  end
end

#sizeObject



90
91
92
# File 'lib/rbs/ast/declarations.rb', line 90

def size
  params.size
end

#skip_validation?(name) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
# File 'lib/rbs/ast/declarations.rb', line 81

def skip_validation?(name)
  var = self[name] or raise
  var.skip_validation
end

#to_json(state = _ = nil) ⇒ Object



58
59
60
61
62
# File 'lib/rbs/ast/declarations.rb', line 58

def to_json(state = _ = nil)
  {
    params: params
  }.to_json(state)
end

#variance(name) ⇒ Object



76
77
78
79
# File 'lib/rbs/ast/declarations.rb', line 76

def variance(name)
  var = self[name] or raise
  var.variance
end