class RBS::Definition
Attributes
ancestors[R]
class_variables[R]
entry[R]
instance_variables[R]
methods[R]
self_type[R]
type_name[R]
Public Class Methods
new(type_name:, entry:, self_type:, ancestors:)
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 287 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
class?()
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 310 def class? entry.is_a?(Environment::ClassEntry) end
class_type?()
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 327 def class_type? self_type.is_a?(Types::ClassSingleton) end
each_type() { |type| ... }
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 372 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
instance_type?()
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 331 def instance_type? self_type.is_a?(Types::ClassInstance) end
interface?()
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 318 def interface? case en = entry when Environment::SingleEntry en.decl.is_a?(AST::Declarations::Interface) else false end end
interface_type?()
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 335 def interface_type? self_type.is_a?(Types::Interface) end
map_method_type(&block)
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 362 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
module?()
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 314 def module? entry.is_a?(Environment::ModuleEntry) end
sub(s)
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 352 def sub(s) 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
type_params()
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 339 def type_params type_params_decl.each.map(&:name) end
type_params_decl()
click to toggle source
# File rbs-3.2.1/lib/rbs/definition.rb, line 343 def type_params_decl case en = entry when Environment::ClassEntry, Environment::ModuleEntry en.type_params when Environment::SingleEntry en.decl.type_params end end