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

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

Defined Under Namespace

Classes: TypeParam

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModuleTypeParams

Returns a new instance of ModuleTypeParams.



17
18
19
# File 'lib/rbs/ast/declarations.rb', line 17

def initialize()
  @params = []
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/rbs/ast/declarations.rb', line 5

def params
  @params
end

Class Method Details

.emptyObject



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

def self.empty
  new
end

Instance Method Details

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



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

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

#[](name) ⇒ Object



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

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

#add(param) ⇒ Object



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

def add(param)
  params << param
  self
end

#each(&block) ⇒ Object



46
47
48
# File 'lib/rbs/ast/declarations.rb', line 46

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  params.empty?
end

#hashObject



32
33
34
# File 'lib/rbs/ast/declarations.rb', line 32

def hash
  params.hash
end

#rename_to(names) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/rbs/ast/declarations.rb', line 70

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



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

def size
  params.size
end

#skip_validation?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

def skip_validation?(name)
  self[name].skip_validation
end

#to_json(*a) ⇒ Object



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

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

#variance(name) ⇒ Object



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

def variance(name)
  self[name].variance
end