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.
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
# File 'lib/rbs/definition.rb', line 297
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.
291
292
293
|
# File 'lib/rbs/definition.rb', line 291
def ancestors
@ancestors
end
|
#class_variables ⇒ Object
Returns the value of attribute class_variables.
295
296
297
|
# File 'lib/rbs/definition.rb', line 295
def class_variables
@class_variables
end
|
#entry ⇒ Object
Returns the value of attribute entry.
290
291
292
|
# File 'lib/rbs/definition.rb', line 290
def entry
@entry
end
|
#instance_variables ⇒ Object
Returns the value of attribute instance_variables.
294
295
296
|
# File 'lib/rbs/definition.rb', line 294
def instance_variables
@instance_variables
end
|
#methods ⇒ Object
Returns the value of attribute methods.
293
294
295
|
# File 'lib/rbs/definition.rb', line 293
def methods
@methods
end
|
#self_type ⇒ Object
Returns the value of attribute self_type.
292
293
294
|
# File 'lib/rbs/definition.rb', line 292
def self_type
@self_type
end
|
#type_name ⇒ Object
Returns the value of attribute type_name.
289
290
291
|
# File 'lib/rbs/definition.rb', line 289
def type_name
@type_name
end
|
Instance Method Details
#class_type? ⇒ Boolean
337
338
339
|
# File 'lib/rbs/definition.rb', line 337
def class_type?
self_type.is_a?(Types::ClassSingleton)
end
|
#each_type(&block) ⇒ Object
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
# File 'lib/rbs/definition.rb', line 384
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
341
342
343
|
# File 'lib/rbs/definition.rb', line 341
def instance_type?
self_type.is_a?(Types::ClassInstance)
end
|
#interface_type? ⇒ Boolean
345
346
347
|
# File 'lib/rbs/definition.rb', line 345
def interface_type?
self_type.is_a?(Types::Interface)
end
|
#map_method_type(&block) ⇒ Object
374
375
376
377
378
379
380
381
382
|
# File 'lib/rbs/definition.rb', line 374
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
362
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/rbs/definition.rb', line 362
def sub(s)
return self if s.empty?
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
349
350
351
|
# File 'lib/rbs/definition.rb', line 349
def type_params
type_params_decl.each.map(&:name)
end
|
#type_params_decl ⇒ Object