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, keyword_init: true) do
  def to_json(*a)
    {
      name: name,
      variance: variance,
      skip_validation: skip_validation,
    }.to_json(*a)
  end
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModuleTypeParams

Returns a new instance of ModuleTypeParams.



20
21
22
# File 'lib/rbs/ast/declarations.rb', line 20

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



57
58
59
# File 'lib/rbs/ast/declarations.rb', line 57

def self.empty
  new
end

Instance Method Details

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



29
30
31
# File 'lib/rbs/ast/declarations.rb', line 29

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

#[](name) ⇒ Object



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

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

#add(param) ⇒ Object



24
25
26
27
# File 'lib/rbs/ast/declarations.rb', line 24

def add(param)
  params << param
  self
end

#each(&block) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/rbs/ast/declarations.rb', line 49

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  params.empty?
end

#hashObject



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

def hash
  params.hash
end

#rename_to(names) ⇒ Object



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

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))
    end
  end
end

#sizeObject



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

def size
  params.size
end

#skip_validation?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#to_json(*a) ⇒ Object



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

def to_json(*a)
  {
    params: params
  }.to_json(*a)
end

#variance(name) ⇒ Object



61
62
63
64
# File 'lib/rbs/ast/declarations.rb', line 61

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