Class: Yoda::Model::TypeExpressions::InstanceType

Inherits:
Base
  • Object
show all
Defined in:
lib/yoda/model/type_expressions/instance_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #map

Constructor Details

#initialize(path) ⇒ InstanceType

Returns a new instance of InstanceType.

Parameters:



11
12
13
# File 'lib/yoda/model/type_expressions/instance_type.rb', line 11

def initialize(path)
  @path = ScopedPath.build(path)
end

Instance Attribute Details

#pathScopedPath (readonly)

Returns:



8
9
10
# File 'lib/yoda/model/type_expressions/instance_type.rb', line 8

def path
  @path
end

Instance Method Details

#change_root(paths) ⇒ self

Parameters:

Returns:

  • (self)


27
28
29
# File 'lib/yoda/model/type_expressions/instance_type.rb', line 27

def change_root(paths)
  self.class.new(path.change_scope(paths))
end

#eql?(another) ⇒ Boolean

Parameters:

  • another (Object)

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/yoda/model/type_expressions/instance_type.rb', line 16

def eql?(another)
  another.is_a?(InstanceType) &&
  path == another.path
end

#hashObject



21
22
23
# File 'lib/yoda/model/type_expressions/instance_type.rb', line 21

def hash
  [self.class.name, path].hash
end

#resolve(registry) ⇒ Array<Store::Objects::Base>

Parameters:

  • registry (Registry)

Returns:



33
34
35
# File 'lib/yoda/model/type_expressions/instance_type.rb', line 33

def resolve(registry)
  [Store::Query::FindConstant.new(registry).find(path)].compact
end

#to_rbs_type(env) ⇒ Object

Parameters:



43
44
45
46
# File 'lib/yoda/model/type_expressions/instance_type.rb', line 43

def to_rbs_type(env)
  name = env.resolve_rbs_type_name(path)
  name ? RBS::Types::ClassInstance.new(name: name, args: [], location: nil) : RBS::Types::Bases::Any.new(location: nil)
end

#to_sString

Returns:

  • (String)


38
39
40
# File 'lib/yoda/model/type_expressions/instance_type.rb', line 38

def to_s
  path.path.to_s
end