Class: RBS::Environment::ClassEntry
- Inherits:
-
Object
- Object
- RBS::Environment::ClassEntry
- Defined in:
- lib/rbs/environment/class_entry.rb
Instance Attribute Summary collapse
-
#context_decls ⇒ Object
readonly
Returns the value of attribute context_decls.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<<(context_decl) ⇒ Object
- #each_decl(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(name) ⇒ ClassEntry
constructor
A new instance of ClassEntry.
- #primary_decl ⇒ Object
- #type_params ⇒ Object
- #validate_type_params ⇒ Object
Constructor Details
#initialize(name) ⇒ ClassEntry
Returns a new instance of ClassEntry.
10 11 12 13 |
# File 'lib/rbs/environment/class_entry.rb', line 10 def initialize(name) @name = name @context_decls = [] end |
Instance Attribute Details
#context_decls ⇒ Object (readonly)
Returns the value of attribute context_decls.
8 9 10 |
# File 'lib/rbs/environment/class_entry.rb', line 8 def context_decls @context_decls end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rbs/environment/class_entry.rb', line 6 def name @name end |
Instance Method Details
#<<(context_decl) ⇒ Object
15 16 17 18 19 |
# File 'lib/rbs/environment/class_entry.rb', line 15 def <<(context_decl) context_decls << context_decl @primary_decl = nil self end |
#each_decl(&block) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File '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 |
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/rbs/environment/class_entry.rb', line 31 def empty? context_decls.empty? end |
#primary_decl ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File '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 |
#type_params ⇒ Object
47 48 49 50 |
# File 'lib/rbs/environment/class_entry.rb', line 47 def type_params validate_type_params primary_decl.type_params end |
#validate_type_params ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File '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 |