class RBS::Definition
Attributes
Public Class Methods
Source
# File bundled-src/rbs-3.10.0/lib/rbs/definition.rb, line 297 def initialize(type_name:, entry:, self_type:, ancestors:) case entry when Environment::ClassEntry, Environment::ModuleEntry # ok 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
Public Instance Methods
Source
# File bundled-src/rbs-3.10.0/lib/rbs/definition.rb, line 320 def class? entry.is_a?(Environment::ClassEntry) end
Source
# File bundled-src/rbs-3.10.0/lib/rbs/definition.rb, line 337 def class_type? self_type.is_a?(Types::ClassSingleton) end
Source
# File bundled-src/rbs-3.10.0/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
Source
# File bundled-src/rbs-3.10.0/lib/rbs/definition.rb, line 341 def instance_type? self_type.is_a?(Types::ClassInstance) end
Source
# File bundled-src/rbs-3.10.0/lib/rbs/definition.rb, line 328 def interface? case en = entry when Environment::SingleEntry en.decl.is_a?(AST::Declarations::Interface) else false end end
Source
# File bundled-src/rbs-3.10.0/lib/rbs/definition.rb, line 345 def interface_type? self_type.is_a?(Types::Interface) end
Source
# File bundled-src/rbs-3.10.0/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
Source
# File bundled-src/rbs-3.10.0/lib/rbs/definition.rb, line 324 def module? entry.is_a?(Environment::ModuleEntry) end
Source
# File bundled-src/rbs-3.10.0/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
Source
# File bundled-src/rbs-3.10.0/lib/rbs/definition.rb, line 349 def type_params type_params_decl.each.map(&:name) end
Source
# File bundled-src/rbs-3.10.0/lib/rbs/definition.rb, line 353 def type_params_decl case en = entry when Environment::ClassEntry, Environment::ModuleEntry en.type_params when Environment::SingleEntry en.decl.type_params end end