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

Inherits:
Base
  • Object
show all
Includes:
_ToJson, MixinHelper, NestedDeclarationHelper, _HashEqual
Defined in:
lib/rbs/ast/declarations.rb,
sig/declarations.rbs

Defined Under Namespace

Classes: Super

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MixinHelper

#each_mixin

Methods included from NestedDeclarationHelper

#each_decl, #each_member

Constructor Details

#initialize(name:, type_params:, super_class:, members:, annotations:, location:, comment:) ⇒ Class

Returns a new instance of Class.

Parameters:



97
98
99
100
101
102
103
104
105
# File 'lib/rbs/ast/declarations.rb', line 97

def initialize(name:, type_params:, super_class:, members:, annotations:, location:, comment:)
  @name = name
  @type_params = type_params
  @super_class = super_class
  @members = members
  @annotations = annotations
  @location = location
  @comment = comment
end

Instance Attribute Details

#annotationsArray[Annotation] (readonly)

Returns the value of attribute annotations.

Returns:



93
94
95
# File 'lib/rbs/ast/declarations.rb', line 93

def annotations
  @annotations
end

#commentComment? (readonly)

Returns the value of attribute comment.

Returns:



95
96
97
# File 'lib/rbs/ast/declarations.rb', line 95

def comment
  @comment
end

#locationloc? (readonly)

Returns the value of attribute location.

Returns:

  • (loc, nil)


94
95
96
# File 'lib/rbs/ast/declarations.rb', line 94

def location
  @location
end

#membersArray[member] (readonly)

Returns the value of attribute members.

Returns:

  • (Array[member])


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

def members
  @members
end

#nameTypeName (readonly)

Returns the value of attribute name.

Returns:



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

def name
  @name
end

#super_classSuper? (readonly)

Returns the value of attribute super_class.

Returns:



92
93
94
# File 'lib/rbs/ast/declarations.rb', line 92

def super_class
  @super_class
end

#type_paramsArray[TypeParam] (readonly)

Returns the value of attribute type_params.

Returns:



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

def type_params
  @type_params
end

Instance Method Details

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



119
120
121
122
123
124
125
# File 'lib/rbs/ast/declarations.rb', line 119

def ==(other)
  other.is_a?(Class) &&
    other.name == name &&
    other.type_params == type_params &&
    other.super_class == super_class &&
    other.members == members
end

#hashObject



129
130
131
# File 'lib/rbs/ast/declarations.rb', line 129

def hash
  self.class.hash ^ name.hash ^ type_params.hash ^ super_class.hash ^ members.hash
end

#to_json(state = nil) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rbs/ast/declarations.rb', line 133

def to_json(state = nil)
  {
    declaration: :class,
    name: name,
    type_params: type_params,
    members: members,
    super_class: super_class,
    annotations: annotations,
    location: location,
    comment: comment
  }.to_json(state)
end

#update(name: self.name, type_params: self.type_params, super_class: self.super_class, members: self.members, annotations: self.annotations, location: self.location, comment: self.comment) ⇒ Declarations::Class

Parameters:

  • name: (TypeName) (defaults to: self.name)
  • type_params: (Array[TypeParam]) (defaults to: self.type_params)
  • members: (Array[member]) (defaults to: self.members)
  • super_class: (Super, nil) (defaults to: self.super_class)
  • annotations: (Array[Annotation]) (defaults to: self.annotations)
  • location: (loc, nil) (defaults to: self.location)
  • comment: (Comment, nil) (defaults to: self.comment)

Returns:



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rbs/ast/declarations.rb', line 107

def update(name: self.name, type_params: self.type_params, super_class: self.super_class, members: self.members, annotations: self.annotations, location: self.location, comment: self.comment)
  self.class.new(
    name: name,
    type_params: type_params,
    super_class: super_class,
    members: members,
    annotations: annotations,
    location: location,
    comment: comment
  )
end