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.



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

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



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

def self.empty
  new
end

Instance Method Details

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



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

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

#[](name) ⇒ Object



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

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

#add(param) ⇒ Object



13
14
15
16
# File 'lib/rbs/ast/declarations.rb', line 13

def add(param)
  params << param
  self
end

#each(&block) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  params.empty?
end

#hashObject



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

def hash
  params.hash
end

#rename_to(names) ⇒ Object



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

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



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

def size
  params.size
end

#skip_validation?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#to_json(*a) ⇒ Object



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

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

#variance(name) ⇒ Object



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

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