# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/class_entry.rb, line 35 def primary_decl @primary_decl ||= nil.tap do # @type break: declaration decl = each_decl.find {|decl| decl.super_class } break decl if decl decl = each_decl.first break decl if decl end || raise("Cannot find primary declaration for #{name}") end
class RBS::Environment::ClassEntry
Represents a class entry in the environment
entry = ClassEntry.new(TypeName.parse("::String")) entry << [nil, declaration] entry << [[nil, TypeName.parse("::Kernel")], declaration]
Attributes
context_decls
[R]
Array[context_decl]
Public Class Methods
(TypeName) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/class_entry.rb, line 10 def initialize(name) @name = name @context_decls = [] end
Public Instance Methods
(context_decl) → self
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/class_entry.rb, line 15 def <<(context_decl) context_decls << context_decl @primary_decl = nil self end
() { (declaration) → void } → void
() → Enumerator[declaration]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/class_entry.rb, line 21 def each_decl(&block) if block context_decls.each do |_, decl| yield decl end else enum_for(__method__ || raise) end end
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/class_entry.rb, line 31 def empty? context_decls.empty? end
Returns true if the entry doesn’t have any declaration
() → declaration
Source
Find the primary declaration of the class
-
Returns the first declaration with super class
-
Returns the first declaration if the declaration doesn’t have super class
() → Array[AST::TypeParam]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/class_entry.rb, line 47 def type_params validate_type_params primary_decl.type_params end
Returns the generics declaration
() → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/class_entry.rb, line 52 def validate_type_params unless context_decls.empty? first_decl, *rest_decls = each_decl.to_a first_decl or raise first_params = first_decl.type_params first_names = first_params.map(&:name) rest_decls.each do |other_decl| other_params = other_decl.type_params unless first_names.size == other_params.size && first_params == AST::TypeParam.rename(other_params, new_names: first_names) raise GenericParameterMismatchError.new(name: name, decl: other_decl) end end end end
Confirms if the type parameters in the declaration are compatible
-
Raises
GenericParameterMismatchErrorif incompatible declaration is detected.