class RBS::Prototype::Runtime::DataGenerator

Public Class Methods

generatable?(target) click to toggle source
# File rbs-3.4.0/lib/rbs/prototype/runtime/value_object_generator.rb, line 212
def self.generatable?(target)
  return false unless RUBY_VERSION >= '3.2'
  return false unless target < Data
  # Avoid direct inherited class like `class Option < Data`
  return false unless target.respond_to?(:members)

  true
end

Private Instance Methods

add_decl_members(decl) click to toggle source
# File rbs-3.4.0/lib/rbs/prototype/runtime/value_object_generator.rb, line 227
def add_decl_members(decl)
  decl.members.concat build_s_new
  decl.members.concat build_s_members
  decl.members.concat build_member_accessors(AST::Members::AttrReader)
end
build_s_new() click to toggle source

def self.new: (untyped foo, untyped bar) -> instance

| (foo: untyped, bar: untyped) -> instance
# File rbs-3.4.0/lib/rbs/prototype/runtime/value_object_generator.rb, line 235
def build_s_new
  [:new, :[]].map do |name|
    new_overloads = []

    new_overloads << AST::Members::MethodDefinition::Overload.new(
      annotations: [],
      method_type: MethodType.new(
        type: Types::Function.empty(Types::Bases::Instance.new(location: nil)).update(
          required_positionals: @target_class.members.map { |m| Types::Function::Param.new(name: m, type: untyped) },
        ),
        type_params: [],
        block: nil,
        location: nil,
      )
    )
    new_overloads << AST::Members::MethodDefinition::Overload.new(
      annotations: [],
      method_type: MethodType.new(
        type: Types::Function.empty(Types::Bases::Instance.new(location: nil)).update(
          required_keywords: @target_class.members.to_h { |m| [m, Types::Function::Param.new(name: nil, type: untyped)] },
        ),
        type_params: [],
        block: nil,
        location: nil,
      )
    )

    AST::Members::MethodDefinition.new(
      name: name,
      overloads: new_overloads,
      kind: :singleton,
      location: nil,
      comment: nil,
      annotations: [],
      overloading: false,
      visibility: nil
    )
  end
end
build_super_class() click to toggle source
# File rbs-3.4.0/lib/rbs/prototype/runtime/value_object_generator.rb, line 223
def build_super_class
  AST::Declarations::Class::Super.new(name: TypeName("::Data"), args: [], location: nil)
end