Class: RBS::Definition
- Inherits:
-
Object
show all
- Defined in:
- lib/rbs/definition.rb
Defined Under Namespace
Modules: Ancestor
Classes: InstanceAncestors, Method, SingletonAncestors, Variable
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(type_name:, entry:, self_type:, ancestors:) ⇒ Definition
Returns a new instance of Definition.
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/rbs/definition.rb', line 201
def initialize(type_name:, entry:, self_type:, ancestors:)
case entry
when Environment::ClassEntry, Environment::ModuleEntry
else
unless entry.decl.is_a?(AST::Declarations::Interface)
raise "Declaration should be a class, module, or interface: #{type_name}"
end
end
unless self_type.is_a?(Types::ClassSingleton) || self_type.is_a?(Types::Interface) || self_type.is_a?(Types::ClassInstance)
raise "self_type should be the type of declaration: #{self_type}"
end
@type_name = type_name
@self_type = self_type
@entry = entry
@methods = {}
@instance_variables = {}
@class_variables = {}
@ancestors = ancestors
end
|
Instance Attribute Details
#ancestors ⇒ Object
Returns the value of attribute ancestors.
195
196
197
|
# File 'lib/rbs/definition.rb', line 195
def ancestors
@ancestors
end
|
#class_variables ⇒ Object
Returns the value of attribute class_variables.
199
200
201
|
# File 'lib/rbs/definition.rb', line 199
def class_variables
@class_variables
end
|
#entry ⇒ Object
Returns the value of attribute entry.
194
195
196
|
# File 'lib/rbs/definition.rb', line 194
def entry
@entry
end
|
#instance_variables ⇒ Object
Returns the value of attribute instance_variables.
198
199
200
|
# File 'lib/rbs/definition.rb', line 198
def instance_variables
@instance_variables
end
|
#methods ⇒ Object
Returns the value of attribute methods.
197
198
199
|
# File 'lib/rbs/definition.rb', line 197
def methods
@methods
end
|
#self_type ⇒ Object
Returns the value of attribute self_type.
196
197
198
|
# File 'lib/rbs/definition.rb', line 196
def self_type
@self_type
end
|
#type_name ⇒ Object
Returns the value of attribute type_name.
193
194
195
|
# File 'lib/rbs/definition.rb', line 193
def type_name
@type_name
end
|
Instance Method Details
#class_type? ⇒ Boolean
239
240
241
|
# File 'lib/rbs/definition.rb', line 239
def class_type?
self_type.is_a?(Types::ClassSingleton)
end
|
#each_type(&block) ⇒ Object
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
# File 'lib/rbs/definition.rb', line 284
def each_type(&block)
if block
methods.each_value do |method|
if method.defined_in == type_name
method.method_types.each do |method_type|
method_type.each_type(&block)
end
end
end
instance_variables.each_value do |var|
if var.declared_in == type_name
yield var.type
end
end
class_variables.each_value do |var|
if var.declared_in == type_name
yield var.type
end
end
else
enum_for :each_type
end
end
|
#instance_type? ⇒ Boolean
243
244
245
|
# File 'lib/rbs/definition.rb', line 243
def instance_type?
self_type.is_a?(Types::ClassInstance)
end
|
#interface_type? ⇒ Boolean
247
248
249
|
# File 'lib/rbs/definition.rb', line 247
def interface_type?
self_type.is_a?(Types::Interface)
end
|
#map_method_type(&block) ⇒ Object
274
275
276
277
278
279
280
281
282
|
# File 'lib/rbs/definition.rb', line 274
def map_method_type(&block)
definition = self.class.new(type_name: type_name, self_type: self_type, ancestors: ancestors, entry: entry)
definition.methods.merge!(methods.transform_values {|method| method.map_method_type(&block) })
definition.instance_variables.merge!(instance_variables)
definition.class_variables.merge!(class_variables)
definition
end
|
#sub(s) ⇒ Object
264
265
266
267
268
269
270
271
272
|
# File 'lib/rbs/definition.rb', line 264
def sub(s)
definition = self.class.new(type_name: type_name, self_type: _ = self_type.sub(s), ancestors: ancestors, entry: entry)
definition.methods.merge!(methods.transform_values {|method| method.sub(s) })
definition.instance_variables.merge!(instance_variables.transform_values {|v| v.sub(s) })
definition.class_variables.merge!(class_variables.transform_values {|v| v.sub(s) })
definition
end
|
#type_params ⇒ Object
251
252
253
|
# File 'lib/rbs/definition.rb', line 251
def type_params
type_params_decl.each.map(&:name)
end
|
#type_params_decl ⇒ Object