# File rbs-1.0.4/lib/rbs/definition.rb, line 266 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
# File rbs-1.0.4/lib/rbs/definition.rb, line 289 def class? entry.is_a?(Environment::ClassEntry) end
# File rbs-1.0.4/lib/rbs/definition.rb, line 306 def class_type? self_type.is_a?(Types::ClassSingleton) end
# File rbs-1.0.4/lib/rbs/definition.rb, line 351 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
# File rbs-1.0.4/lib/rbs/definition.rb, line 310 def instance_type? self_type.is_a?(Types::ClassInstance) end
# File rbs-1.0.4/lib/rbs/definition.rb, line 297 def interface? case en = entry when Environment::SingleEntry en.decl.is_a?(AST::Declarations::Interface) else false end end
# File rbs-1.0.4/lib/rbs/definition.rb, line 314 def interface_type? self_type.is_a?(Types::Interface) end
# File rbs-1.0.4/lib/rbs/definition.rb, line 341 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
# File rbs-1.0.4/lib/rbs/definition.rb, line 293 def module? entry.is_a?(Environment::ModuleEntry) end
# File rbs-1.0.4/lib/rbs/definition.rb, line 331 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