# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/module_entry.rb, line 34 def primary_decl each_decl.first or raise end
class RBS::Environment::ModuleEntry
Represents a class entry in the environment
entry = ModuleEntry.new(TypeName.parse("::Kernel")) entry << [nil, declaration] entry << [[nil, TypeName.parse("::Object")], 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/module_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/module_entry.rb, line 15 def <<(context_decl) context_decls << context_decl self end
() { (declaration) → void } → void
() → Enumerator[declaration]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/module_entry.rb, line 20 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/module_entry.rb, line 30 def empty? context_decls.empty? end
Returns true if the entry doesnβt have any declaration
() → declaration
Source
Returns the first declaration
This method helps using the class with ClassEntry objects.
() → Array[AST::Declarations::Module::Self]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/module_entry.rb, line 43 def self_types each_decl.flat_map do |decl| decl.self_types end.uniq end
() → Array[AST::TypeParam]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/environment/module_entry.rb, line 38 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/module_entry.rb, line 49 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.